This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.
1 / 5
Jan 2019

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.

    {
      "capabilities":
            [
              {
                    "browserName":"Android Nexus4",
                    "version":"7.1.1",
                    "platform":"ANDROID",
                    "maxInstances": 1
              }
            ],
        "configuration":
        {
          "cleanUpCycle":2000,
          "timeout":30000,
          "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
          "url": "http://127.0.0.1:4724/wd/hub",
          "host": "127.0.0.1",
          "port": 4724,
          "maxSession": 1,
          "register": true,
          "registerCycle": 5000,
          "hubPort": 4445,
          "hubHost": "127.0.0.1",
          "session-override": true
        }
    }

{
“capabilities”:
[
{
“browserName”:“Android Pixel”,
“version”:“5.1.1”,
“platform”:“ANDROID”,
“maxInstances”: 1
}
],
“configuration”:
{
“cleanUpCycle”:2000,
“timeout”:30000,
“proxy”: “org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”: “http://127.0.0.1:4734/wd/hub”,
“host”: “127.0.0.1”,
“port”: 4734,
“maxSession”: 1,
“register”: true,
“registerCycle”: 5000,
“hubPort”: 4445,
“hubHost”: “127.0.0.1”,
“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"/>
    <classes>
        <class name="testClasses.android.VerifyOnboardingScreen"/>
    </classes>
</test>

<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"/>
    <classes>
        <class name="testClasses.android.VerifyOnboardingScreen"/>
    </classes>
</test>

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, "co.app");
            capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "co.app.GCSplashActivity");
            capabilities.setCapability("automationName", "uiautomator2");
            capabilities.setCapability("app", resourcesPath + "/android/app.apk");

            driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4445/wd/hub"), capabilities);
            configureDriver();
            break;
  • created

    Jan '19
  • last reply

    Jan '19
  • 4

    replies

  • 373

    views

  • 2

    users

  • 1

    link

@Denys_Voskovets Denis - Add some magic:

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

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.