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.

    {
      "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;

@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.

@Denys_Voskovets you looking into correct direction :slight_smile:

Have a look at my article describing a solution of distributed parallel execution of Appium test with Selenium Grid and Jenkins.

@hemantbanafal we use up to 10 Android + 10 iOS devices on one macMini with 16Gb. I hardly believe someone needs more :-). But if really needed 32Gb will solve it :slight_smile: cause CPU usage is very slow using real devices.

1 Like

@Aleksei Thank you for your feedback. I completely agree with your point but the solution is for virtual devices. You cannot run more than 4 simulators or 2 emulator on 4 core Mac CPU. Also in the end of the article I have mentioned how to run on real devices without increasing the machines. And the whole scalable solution will help you making your regression suite as part of CI. As you can reduce the execution time upto 5-10 mins. :slight_smile:

Agree. The only note with android it is cheaper to buy phones in times. With iOS macMini with simulators cheaper.

2 Likes

Hi Aleksei,

Im abit confused is it really major difference to achive parallel testing using selenium grid over just using same appium server using different port and bootstrap

I have performed parallel test using the two technique and always the way using selenium grid is always slower

Can you please provide more info whats the actual benifit pros and cons using selenium grid over appium functions (port number ,wdalocal port , …etc)

@Amrkamel1 hi. I never used selenium grid. Never needed. I use macMini and real phones. One macMini (i7 and 16Gb RAM) easily works with 10 Android and 10 iPhones (with using recording of test feature) simultaniesly.

1 Like