Mobile Test Automation
Master mobile test automation using Appium and other tools. This is a foundational concept in quality assurance and test automation that professional developers rely on daily. The explanations below are written to be beginner-friendly while covering the depth and nuance that comes from real-world Software Testing experience. Take your time with each section and practice the examples
50 min•By Priygop Team•Last updated: Feb 2026
Appium Setup and Configuration
Example
// Appium Maven Dependencies
<dependencies>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>8.6.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.8.0</version>
</dependency>
</dependencies>
// Appium Desired Capabilities
public class AppiumConfig {
public static DesiredCapabilities getAndroidCapabilities() {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "13");
caps.setCapability("deviceName", "Pixel 7");
caps.setCapability("app", "/path/to/app.apk");
caps.setCapability("automationName", "UiAutomator2");
caps.setCapability("noReset", true);
caps.setCapability("fullReset", false);
return caps;
}
public static DesiredCapabilities getIOSCapabilities() {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("platformName", "iOS");
caps.setCapability("platformVersion", "16.0");
caps.setCapability("deviceName", "iPhone 14");
caps.setCapability("app", "/path/to/app.app");
caps.setCapability("automationName", "XCUITest");
caps.setCapability("noReset", true);
caps.setCapability("fullReset", false);
return caps;
}
}
// Basic Appium Test
public class MobileLoginTest {
private AndroidDriver driver;
@BeforeMethod
public void setUp() {
DesiredCapabilities caps = AppiumConfig.getAndroidCapabilities();
driver = new AndroidDriver(new URL("http://localhost:4723"), caps);
}
@Test
public void testLogin() {
// Find elements
WebElement usernameField = driver.findElement(By.id("username"));
WebElement passwordField = driver.findElement(By.id("password"));
WebElement loginButton = driver.findElement(By.id("loginButton"));
// Perform actions
usernameField.sendKeys("testuser");
passwordField.sendKeys("password123");
loginButton.click();
// Verify result
WebElement welcomeMessage = driver.findElement(By.id("welcomeMessage"));
Assert.assertTrue(welcomeMessage.isDisplayed());
}
@AfterMethod
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
}Mobile Test Automation Best Practices
Example
// Page Object Model for Mobile
public class LoginPage {
private AndroidDriver driver;
// Locators
private By usernameField = By.id("username");
private By passwordField = By.id("password");
private By loginButton = By.id("loginButton");
private By errorMessage = By.id("errorMessage");
public LoginPage(AndroidDriver driver) {
this.driver = driver;
}
public void enterUsername(String username) {
driver.findElement(usernameField).sendKeys(username);
}
public void enterPassword(String password) {
driver.findElement(passwordField).sendKeys(password);
}
public void clickLogin() {
driver.findElement(loginButton).click();
}
public boolean isErrorMessageDisplayed() {
return driver.findElement(errorMessage).isDisplayed();
}
public String getErrorMessage() {
return driver.findElement(errorMessage).getText();
}
}
// Mobile Test Utilities
public class MobileTestUtils {
public static void waitForElement(AndroidDriver driver, By locator, int timeout) {
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(timeout));
wait.until(ExpectedConditions.presenceOfElementLocated(locator));
}
public static void scrollToElement(AndroidDriver driver, String text) {
driver.findElement(AppiumBy.androidUIAutomator(
"new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(new UiSelector().text(\"" + text + "\"))"));
}
public static void swipe(AndroidDriver driver, int startX, int startY, int endX, int endY) {
TouchAction touchAction = new TouchAction(driver);
touchAction.press(PointOption.point(startX, startY))
.moveTo(PointOption.point(endX, endY))
.release()
.perform();
}
public static void takeScreenshot(AndroidDriver driver, String fileName) {
File screenshot = driver.getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(screenshot, new File("screenshots/" + fileName + ".png"));
} catch (IOException e) {
e.printStackTrace();
}
}
}