Selenium Grid and parallel execution for android


Tried to setup parallel execution with selenium grid for two android emulators. But My tests firstly run on 1 device, after finishing, they starts on the 2 device.
Please help, how to run test simultaneously on two devices.

How I run it.

  1. Creating Hub. java -jar selenium-server-standalone-3.14.0.jar -role hub -port 4445

  2. Launching two emulators. with command adb devices i found their udid.

  3. Run 2 appium servers.
    appium --nodeconfig ~/pathtonode/node_1 -p 4724 --suppress-adb-kill-server --bootstrap-port 4824 -U emulator-5554

    appium --nodeconfig ~/TeamWorkAndroid/src/main/resources/appium_node_config/node_2 -p 4734 --suppress-adb-kill-server --bootstrap-port 4834 -U emulator-5556

This is my nodes.

                    "browserName":"Android Nexus4",
                    "maxInstances": 1
          "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
          "url": "",
          "host": "",
          "port": 4724,
          "maxSession": 1,
          "register": true,
          "registerCycle": 5000,
          "hubPort": 4445,
          "hubHost": "",
          "session-override": true

“browserName”:“Android Pixel”,
“maxInstances”: 1
“proxy”: “org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”: “”,
“host”: “”,
“port”: 4734,
“maxSession”: 1,
“register”: true,
“registerCycle”: 5000,
“hubPort”: 4445,
“hubHost”: “”,
“session-override”: true

My testng.xml.

<?xml version="1.0" encoding="UTF-8"?>
<test name="Nexus 5X">
    <parameter name="platform" value="android"/>
    <parameter name="udid" value="emulator-5554"/>
    <parameter name="platformVersion" value="7.1.1"/>
    <parameter name="noReset" value="false"/>
        <class name=""/>

<test name ="Emulator2">
    <parameter name="platform" value="android"/>
    <parameter name="udid" value="emulator-5556"/>
    <parameter name="platformVersion" value="5.1.1"/>
    <parameter name="noReset" value="false"/>
        <class name=""/>

Method where driver starts.

@Parameters({"platform", "udid", "platformVersion", "noReset"})

@BeforeMethod(alwaysRun = true)

public void setUp
                String platform,
                String udid,
                String platformVersion,
                String noReset
        ) throws Exception {

    String resourcesPath = new File("src/main/resources/app").getAbsolutePath();

    DesiredCapabilities capabilities = new DesiredCapabilities();

    switch (platform.toLowerCase()) {

        case "android":
            capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");
            capabilities.setCapability(MobileCapabilityType.UDID, udid);
            capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, platformVersion);
            capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
            capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "");
            capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "");
            capabilities.setCapability("automationName", "uiautomator2");
            capabilities.setCapability("app", resourcesPath + "/android/app.apk");

            driver = new AndroidDriver<MobileElement>(new URL(""), capabilities);


@Denys_Voskovets Denis - Add some magic:

<suite name="My suite" parallel="tests" thread-count="2">
  <test name="Nexus 5X" >
   <!-- your parameters -->
      <class name=""  />
  <test name="Emulator2" >
   <!-- your parameters -->
      <class name=""  />

it will start in parallel and you will meet with other problems… but this is another story


Thank you Aleksey.

You are right. Now tests starts simultaneously but they are using one driver, or i’m wrong. If one test fail - test on another device also will fail. Visually test is executing only on one device.
Can you suggest what i’m doing wrong to setup parallel execution?


Maybe I found a way. To have different drivers we should use ThreadLocal.
I created new simple project with one test and it works.


@Denys_Voskovets you looking into correct direction :slight_smile: