Appium Parallel Execution using TestNG

This is the follow-up post on the Selenium Grid for Appium mobile automation.

Continuing from the example, I hope you have grid hub running with two various appium nodes which has unique applicationName.

This post will focus on showing you on how we execute same tests across multiple devices in parallel. Because, often as test engineers, we have to sign-off our tests in various mobile platforms and devices. Let’s get into action.

Create a TestNG class as follows:

package com.vimalselvam.appium;

import io.appium.java_client.MobileBy;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.*;


public class AppiumTest {

 private AndroidDriver driver;
 private String applicationName;

 @Factory(dataProvider = "parallelDp")
 public AppiumTest(String applicationName) {
   this.applicationName = applicationName;

 @DataProvider(name = "parallelDp")
 public static Object[][] parallelDp() {
   return new Object[][] {
     {"Samsung S4"},
     {"Samsung S5"}

 public void setup() throws MalformedURLException {
   DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
   desiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "ANDROID");
   desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "ANDROID");
   desiredCapabilities.setCapability("applicationName", this.applicationName);
   desiredCapabilities.setCapability(MobileCapabilityType.APP, "");
   driver = new AndroidDriver(new URL(""), desiredCapabilities);

 public void launchTest() throws InterruptedException {
   System.err.println("Thread id: " + Thread.currentThread().getId());

 @Test(dependsOnMethods = {"launchTest"})
 public void clickTest() {

 public void teardown() {
   if (driver != null) {

Note here, I’ve created a @Factory constructor with the data provider called parallelDp. Refer here for more about @Factory. The data provider method produces two String objects of the applicationName which are the same as that I had created during my appium node configuration. Make sure the applicationName here are matches with your node configurations.

I am sure you don’t want me to explain the rest of the test code which simply explains by itself. Let’s move on.

Now create your TestNG Suite xml file as follows:

<!DOCTYPE suite SYSTEM "">
<suite name="Test" verbose="1" data-provider-thread-count="2" thread-count="2" parallel="classes">
  <test name="TestClass" thread-count="2" parallel="instances">
      <class name="com.vimalselvam.appium.AppiumTest" />

I’ve set the suite parallel attribute as classes, so that it will create two instances of my test class in parallel as specified in my thread-count. That’s it, execute and see the magic in the below video.

Appium Parallel Execution