
Mobile Automation using Appium on Android and IOS Devices
The world of mobile applications is growing by leaps and bounds, and so is the need to ensure a seamless user experience across the different platforms and devices available in the market. Appium, an open-source test automation framework, has revolutionized the way developers and testers approach mobile application testing, enabling them to meet this critical need. It comes with features like cross-platform compatibility and intuitive design, which make Appium the go-to solution for streamlining the testing process. Not only does it save time and resources, but it also helps in delivering high-quality mobile applications. Learn Mobile Automation using Appium on Android and iOS Devices to test apps efficiently with cross-platform compatibility and advanced automation tools.
What is Appium:
Appium is an open-source automation testing tool used to test mobile applications — both native, hybrid, and mobile web apps — on Android, iOS, and Windows platforms.
What Appium Does:
Appium allows you to write test scripts that can simulate user interactions (like taps, swipes, typing, etc.) on mobile apps and verify app behavior.
It’s based on the WebDriver protocol, the same one used by Selenium for web testing — meaning you can reuse skills and code between web and mobile testing.
App Types Supported
· Native apps → Built using iOS SDK or Android SDK.
· Hybrid apps → Contain a webview (HTML + native).
· Mobile web apps → Accessed via a mobile browser (like Chrome or Safari).
Architecture Overview:
Appium follows a client-server architecture:
1. Client – Your test code (written in Java/Python/etc.) sends commands via the Appium Client Library.
2. Server – The Appium Server (Node.js-based) receives commands and routes them to the correct platform driver (like UIAutomator2 for Android or XCUITest for iOS).
3. Device – The actual mobile device or emulator/simulator where the test runs.
Prerequisites for Appium:
To start using Appium testing, your system needs to be equipped with certain prerequisites. In this section, we will see how you can set your system up for mobile test automation with Appium.
System Requirements:
1. Operating System: Appium tests can run on Windows, macOS, or Linux operating systems. However, you will need a macOS machine if you wish to test iOS applications since Xcode is only available on macOS.
2. Java Development Kit(JDK): Since we will be using Java for our article, you need to install Java in your system. The latest version can be downloaded from the official website.
3. Node.js: Appium automation framework is built on top of Node.js, so you’ll need to have Node.js installed in your system. You can download it from the official Node.js website.
4. Android SDK(for Android testing): If you need to test Android applications, you will require the Android SDK, which can be downloaded with Android Studio. It can be downloaded from the Android Studio website or directly from the Android SDK command-line tools.
5. Xcode(for iOS testing): For iOS application testing, XCode should be installed on your macOS machine. It is an integrated development environment provided by Apple for iOS development.
Setting up the Environment
1. Android Environment: Once you have installed the Android SDK, you will have to set up the Android environment by configuring the Android Virtual Device (AVD) Manager. It will help you create and manage Android emulators for testing purposes. Also, you may need to enable USB debugging on your physical Android devices for testing.
2. iOS Environment: For testing iOS applications, you will require a valid Apple Developer account to access the necessary tools and resources. You will have to configure code signing and provisioning profiles so that you can deploy and test your iOS applications on real devices and simulators.
To start using Appium mobile testing, you need to set up either Real Devices or emulators or simulators. Let us see how we can set them up for the Appium testing tool
Setting up Real Devices:
1. Android Devices: To set up a real Android device for Appium test automation, you first need to enable USB debugging on the device. Once this is done, you can connect your device to the system and see it listed in the available devices list. You may need to install the appropriate device drivers on your computer to ensure proper communication between Appium and the physical device.
2. iOS Devices: To test real iOS device applications, you need to have a valid Apple developer account. You will also need to configure code signing and provisioning profiles to deploy and test your iOS applications on real devices.
3. Using the TestGrid Real Device Cloud: TestGrid offers a wide range of real devices on its cloud. You can select from several real devices with different configurations it. It can be integrated into your code just like other real devices, and the code can be executed on these cloud devices just like the real devices.
Writing your First Appium Test:
After you have set up Appium and the required prerequisites, let’s dive into writing our first Appium test automation script. Let us go through the steps of beginning our journey to write Appium tests.
Choosing a Programming Language
Appium supports multiple programming languages like Java, Python, Ruby, C#, etc, and one can choose from their preferred language to start automating tests. For this article, we will be using Java as the programming language.
Setting up the Test Automation Framework
Depending on the programming language you choose, you can set up a test automation framework. For example, you can use TestNG or JUnit with Java, or Pytest if using Python. We will be using TestNG in our example.
Explore Other Demanding Courses
No courses available for the selected domain.
Creating our First Appium Test Script
We will create a new Maven Project in Eclipse( you can also choose IntelliJ Idea as the IDE) and add the following dependencies in the pom.xml file.
Step 1: Prerequisites
Before writing code, make sure you have these ready:
1. Java JDK (version 11 or later)
2. Android Studio (with an emulator configured)
3. Appium Server (install via Node.js)
4. npm install -g appium
5. Appium Inspector (optional, for finding element locators)
6. Maven (for dependency management)
7. An IDE – IntelliJ IDEA or Eclipse
Step 2: Maven Project Setup
Create a new Maven project and add the following dependencies in your pom.xml:
<dependencies>
<!-- Appium Java Client -->
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>9.2.2</version>
</dependency>
<!-- TestNG -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.10.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Step 3: Basic Appium + TestNG Code
Here’s a simple example that opens an Android app and clicks a button.
package tests;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.net.MalformedURLException;
import java.net.URL;
public class FirstAppiumTest {
AppiumDriver driver;
@BeforeClass
public void setUp() throws MalformedURLException {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
caps.setCapability(MobileCapabilityType.DEVICE_NAME, "emulator-5554"); // Use your emulator/device name
caps.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");
caps.setCapability(MobileCapabilityType.APP, "C:\\path\\to\\your\\demo.apk"); // Path to your app
// Connect to Appium Server
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), caps);
}
@Test
public void testAppLaunch() {
System.out.println("App launched successfully!");
// Example: click a button
driver.findElement(By.id("com.example.demo:id/btn_start")).click();
// Example: type text
driver.findElement(By.id("com.example.demo:id/input_name")).sendKeys("Appium with TestNG");
}
@AfterClass
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
}
Step 4: Run the Test
1. Start the Appium server:
Appium
Run your TestNG test:
· In IntelliJ: right-click → Run 'FirstAppiumTest'
· Or via Maven:
mvn test
Watch your emulator — it should:
· Open the app
· Click the button
· Type text in a field
Do visit our channel to learn more: SevenMentor
Author:-