Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk10 min

How to Use Appium with TestNG for Mobile App Testing

Learn how TestNG, the Appium Java client, the Appium server, and platform drivers work together to automate Android and iOS mobile tests.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To use Appium with TestNG, write Java tests that TestNG discovers and runs, use Appium’s Java client to send commands to a running Appium server, and install the Appium driver for the platform you want to automate. TestNG organizes test cases and their setup and cleanup; Appium connects those tests to a mobile device, emulator, or hosted device.

This guide walks through a local Android setup first, then explains what changes for iOS, how to run and organize tests, and how to diagnose common session failures. Appium and TestNG versions, driver prerequisites, and client APIs change, so select mutually compatible current releases and check the documentation for your chosen driver before relying on a configuration.

As an Amazon Associate I earn from qualifying purchases.

How Appium and TestNG fit together

These tools do different jobs. TestNG discovers test methods, runs them, and invokes lifecycle hooks. A test method uses the Appium Java client, which is built on Selenium, to send WebDriver commands to the Appium server. The server routes the session to an installed platform driver, which communicates with the target device or emulator.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

That distinction matters during setup: installing the Appium server alone does not let it automate Android or iOS. The Appium project warns that installing the core server “cannot automate anything on its own”; you must also install a driver for your target platform.

What you need before writing a test

  • A Java development environment and a project build tool such as Maven or Gradle.
  • The Appium Java client and TestNG on the test classpath. Check the Appium Java client’s current compatibility information before choosing its version; the client depends on Selenium.
  • The Appium server and the platform driver you intend to use.
  • An Android emulator or device, or an iOS simulator or device, configured according to that driver’s current prerequisites.
  • A test app or a browser target, plus any required device identifiers and permissions.

There is no single version combination or device configuration that applies unchanged to every project. Confirm the prerequisites for your chosen platform driver and the API syntax for your Java client release.

Add Appium and TestNG to a Java project

Maven dependencies

Add the libraries to your project’s test dependencies. The version properties below are values for you to define in your Maven properties or dependency management after checking current release and compatibility information; they are not literal version numbers.

<properties>
  <appium.java.client.version>YOUR_COMPATIBLE_VERSION</appium.java.client.version>
  <testng.version>YOUR_TESTNG_VERSION</testng.version>
</properties>

<dependencies>
  <dependency>
    <groupId>io.appium</groupId>
    <artifactId>java-client</artifactId>
    <version>${appium.java.client.version}</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>${testng.version}</version>
    <scope>test</scope>
  </dependency>
</dependencies>

Gradle dependencies

dependencies {
    testImplementation("io.appium:java-client:$appiumJavaClientVersion")
    testImplementation("org.testng:testng:$testngVersion")
}

tasks.test {
    useTestNG()
}

Define appiumJavaClientVersion and testngVersion in your Gradle configuration with versions you have checked for compatibility. Build-runner configuration differs between projects; do not assume a Maven or Gradle test command will use TestNG unless the project is configured to do so.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Install the Appium server and the target driver

Install the Appium server using its supported installation method, then install the driver for the platform you will automate. The Appium CLI workflow commonly uses appium driver install; for example, the driver identifiers used for Android UIAutomator2 and iOS XCUITest are shown below. Verify the identifiers and prerequisites against the current server and driver documentation.

appium driver install uiautomator2
# For an iOS target, on a suitably configured macOS environment:
appium driver install xcuitest

Start the server in a terminal:

appium

The Appium CLI uses port 4723 by default in the documented server context. If you choose a different port or server path, use the same endpoint in your Java client. Keep the server running while the tests execute.

Set capabilities for the target session

Capabilities are inputs to session creation. At minimum, set platformName and appium:automationName. Add only the other settings required for your app, device, and driver. Under W3C capability conventions, Appium-specific capabilities use the appium: prefix.

Capability Purpose When to set it
platformName Names the platform, such as Android or iOS. Every session.
appium:automationName Selects the platform automation driver, commonly UiAutomator2 for Android or XCUITest for iOS. Every session; confirm the driver name and support for your version.
appium:app Identifies an app to install or launch, commonly by a path or driver-supported app location. When testing an app rather than an already prepared target. Follow the driver’s rules for accepted values.
appium:deviceName Provides a device name or selection hint where the driver uses it. When required or useful for your target; it may not uniquely identify a connected device.
appium:udid Identifies a particular device by its unique device identifier. When selecting a specific connected device or emulator is necessary.
appium:platformVersion Specifies the operating-system version. When needed to select or constrain the target; use a value appropriate to the available device.

Capabilities cannot be changed after the session starts. To change them, end the session and create another with the new values. Reset-related settings such as noReset and fullReset are driver-sensitive: check their exact effects before using them, especially if tests depend on clean application state.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Create an Android TestNG test

The example below uses the Appium Java client’s typed Android options and creates one driver per test method. Confirm constructor and options syntax against the client version you selected. Replace the app path and device name with values valid for your environment, and change the example test locator to an element in your own app.

package example;

import java.net.URL;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.options.UiAutomator2Options;
import org.openqa.selenium.By;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class AndroidSmokeTest {
    private AndroidDriver driver;

    @BeforeMethod
    public void startSession() throws Exception {
        UiAutomator2Options options = new UiAutomator2Options()
                .setDeviceName("Android Emulator")
                .setApp("/absolute/path/to/your-app.apk");

        options.setPlatformName("Android");
        options.setAutomationName("UiAutomator2");

        driver = new AndroidDriver(
                new URL("http://127.0.0.1:4723"), options);
    }

    @Test
    public void appShowsExpectedElement() {
        Assert.assertTrue(
                driver.findElement(By.id("your.package:id/home_title")).isDisplayed());
    }

    @AfterMethod(alwaysRun = true)
    public void stopSession() {
        if (driver != null) {
            driver.quit();
            driver = null;
        }
    }
}

setDeviceName is an example selection value, not a guarantee that a particular emulator will be found. If your environment needs a specific emulator or connected phone, identify it as the driver expects and set its UDID where appropriate. The sample’s app path and element ID are environment-specific and must be replaced. A successful session confirms that the server, driver, capabilities, and target can connect; a failing assertion may instead indicate that the app state or locator differs from the test’s expectation.

Using an iOS target

The lifecycle pattern stays the same, but the driver, options, target, and environment requirements change. The following illustrates the shape of an iOS setup; use the current XCUITest driver and Java client documentation to confirm the options available for your versions and device.

import java.net.URL;

import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.ios.options.XCUITestOptions;
import org.testng.annotations.BeforeMethod;

private IOSDriver driver;

@BeforeMethod
public void startIosSession() throws Exception {
    XCUITestOptions options = new XCUITestOptions()
            .setDeviceName("iPhone Simulator")
            .setApp("/absolute/path/to/your-app.app");

    options.setPlatformName("iOS");
    options.setAutomationName("XCUITest");

    driver = new IOSDriver(new URL("http://127.0.0.1:4723"), options);
}

This is a session-setup fragment, not a complete standalone test class. iOS automation has platform-specific setup requirements, and this example does not imply that an iOS simulator or device can be used on every host operating system.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the right TestNG lifecycle scope

One session per test method

@BeforeMethod and @AfterMethod create and close a session around each test. This provides better isolation: a test is less likely to inherit screen state or application changes left by a previous method. It also creates more sessions, so the setup may take longer than sharing one; that is a lifecycle trade-off, not a measured performance claim.

One session per class

@BeforeClass and @AfterClass can share a session across methods in a class. This reduces repeated setup, but tests must manage state deliberately. A method that changes the app or device can affect later methods, and failures can leave the shared session in an unexpected state.

Other hooks

TestNG provides before/after hooks at method, class, test, suite, and group scope, and hooks can be inherited from a superclass. Choose the narrowest scope that matches your isolation needs. Regardless of scope, use cleanup hooks so a failed assertion does not leave a session running; alwaysRun = true is useful for teardown methods where supported by your TestNG setup.

Run and organize the suite

A testng.xml file can define a suite, name one or more tests, and select classes. For example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Mobile smoke suite">
  <test name="Android smoke">
    <classes>
      <class name="example.AndroidSmokeTest"/>
    </classes>
  </test>
</suite>

Use your project’s configured build runner to execute the suite as part of repeatable team workflows. TestNG also supports command-line execution, but the exact invocation depends on how TestNG and your project’s classpath are set up. For Maven or Gradle, configure the relevant test runner and suite selection for your project rather than copying a command whose plugin and assumptions do not match it.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose an emulator, real device, or hosted target

Target Useful when Trade-offs to consider
Emulator or simulator You want a locally controlled target for iterative development and have it configured. It may not reproduce hardware-specific behavior. Reproducibility depends on keeping the virtual device configuration consistent.
Physical device You need to check behavior that depends on real hardware or a particular device. It requires access to and configuration of the device. No particular phone is mandatory; use the identity and connection settings required by the driver.
Hosted device You need access to devices managed outside your local machine. Appium can be used with cloud-hosted execution, but provider support, device coverage, network requirements, and cost vary. Verify those details with a provider before choosing one.

For local iteration, an already configured emulator or simulator may be sufficient. Add real devices when your test question depends on hardware or device-specific behavior, not simply because Appium is being used.

Troubleshoot common setup failures

  • The server starts, but the session says no driver is available. The core server is installed, but the platform driver may not be. Install the driver for the target platform and check that it is available to the server installation you are running.
  • The Java client cannot connect to the server. Check that Appium is running, that the URL and port in the Java test match the server, and that a local firewall or network setting is not blocking the connection. If you configured a non-default server path, include the correct path.
  • Session creation rejects capabilities. Check the required platform and automation capabilities, the appium: prefix on Appium-specific W3C capabilities, and whether each value is supported by the chosen driver. Capabilities are fixed for the session, so change them by starting a new session.
  • The server cannot find the device or emulator. Confirm that the target is available to the host and that the selected identity matches it. A device name may not uniquely select a connected target; use the driver’s supported device-selection method.
  • The app does not launch. Verify the app path or target value, file accessibility, and any platform-specific signing, installation, or driver prerequisites. Do not assume Android and iOS accept the same app artifact or capability values.
  • The test cannot find an element. Confirm the app is on the expected screen, the locator matches the current UI, and the element has appeared before the lookup. A session can be healthy even when a test’s locator or timing assumption is wrong.
  • A later test fails after an earlier one passed. With a shared session, earlier methods may have altered app state. Use method-level sessions for isolation or add explicit state setup and cleanup suited to the test.
  • Teardown does not run after a failure. Put session cleanup in an after hook and configure it to run after failed tests where supported. Check that the driver reference is non-null before calling quit().

Or skip the browser setup

Appium is for automating mobile apps and devices. ScreenshotNeo is a separate website screenshot API; it does not replace Appium or capture your mobile app’s device session. It can be useful when your workflow also needs clean screenshots of web pages. One GET request returns an image or PDF, and the API response indicates page verdict and billing status.

For example, capture a page as WebP with cURL (see the ScreenshotNeo API documentation for options):

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo removes supported cookie and consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. Its MCP server gives AI agents tools for screenshots and PDFs. The free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000. See ScreenshotNeo for the service details.

Sign up for 1,000 free screenshots a month with no card.

Frequently Asked Questions

Do Appium and TestNG replace one another?

No. TestNG runs and organizes tests; Appium provides the client-server connection and platform driver used to automate a mobile target.

Can I use TestNG with Appium in a Java project?

Yes. Add the Appium Java client and TestNG as test dependencies, then use TestNG annotations to manage tests and driver lifecycle.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.