TiredOfProgramming
TiredOfProgramming

Reputation: 855

TestNG parallel tests are not running on 2 real android devices.

The issue described below is the problem that I've been struggling for about several weeks. I'm trying to run my appium parallel tests using testng.xml file on 2 real android physical devices.So, here is the story: I have 2 packages (each package for each real android device) in my Eclipse project, each package contains several page object classes that only belong to that package (like home page, find a cruise, select options, payment and etc.) and one class that is an actual (smoke) test. When I open appium server from Appium UI and manually start it, each smoke test for each mobile device run perfectly and smoothly. But the problem came when I decided to run each smoke test on its appropriate mobile device parallel. Using TestNG.xml file didn't work for me. What's happening is testNG.xml file takes one smoke test script and run it only on one android device (randomly choosing them even thought adb devices shows that both android devices connected properly), than taking second smoke test script and runs it on the same android device. I've registered 2 appium server instances on remote Selenium Grid - didn't help; I've registered 2 appium server instances on local Selenium Grid - didn't help; I've opened 2 appium server instances programmatically from the script - didn't help. If someone who already performed parallel appium/selenium tests on real android devices please advise. Below is the technical description of my testNG.xml file

I've already tried there variants of testNG.xml file:

     <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
        <suite name="Suite" parallel = "classes" thread-count = "2" verbose = "1">
            <test name = "SomeTest">
            <classes>
               <class name="package1.SamsungGalaxyTab4Smoke_Test"/>
                   <class name="package2.SamsungGalaxyS5SmokeTest"/>
              </classes>
          </test> <!-- Test -->
        </suite> <!-- Suite -->   
    *******************************************************************************

     <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
        <suite name="Suite" parallel = "methods" thread-count = "2" verbose = "1">
            <test name = "SomeTest">
            <classes>
               <class name="package1.SamsungGalaxyTab4Smoke_Test"/>
                   <class name="package2.SamsungGalaxyS5SmokeTest"/>
              </classes>
          </test> <!-- Test -->
        </suite> <!-- Suite -->
********************************************************************************

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
    <suite name="Suite" parallel = "tests" thread-count = "2" verbose = "1">
        <test name = "Test1">
        <classes>
           <class name="package1.SamsungGalaxyTab4SmokeTest"/>
          </classes>
    </test>
    <test>
    <classes>
              <class name="package2.SamsungGalaxyS5SmokeTest"/>
      </test> <!-- Test -->
    </suite> <!-- Suite --> 

Below is the smoke test desired capabilities and starting the server script:

First android device

@BeforeMethod
    public void setup() throws Exception, IOException, MalformedURLException {

        ServerArguments serverArguments = new ServerArguments();
        serverArguments.setArgument("--address", "10.100.225.196");
        serverArguments.setArgument("--local-timezone", true);
        serverArguments.setArgument("--port", "5008");
        serverArguments.setArgument("--session-override", true);
        AppiumServer appiumserver = new AppiumServer(serverArguments);
        if (appiumserver.isServerRunning()){
            appiumserver.stopServer();
        }
        appiumserver.startServer();
        if (appiumserver.isServerRunning()){
        System.out.println("Appium server for Galaxy S5 has been started successfully" );
        }else {
            System.out.println("Appium server for Galaxy S5 has not been started successfully" );
        }
        Thread.sleep(10000);
        DesiredCapabilities cap = new DesiredCapabilities();
        cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium"); 
        cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android device");
        cap.setCapability("--udid", "69d3br21");
        cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
        cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1.1");
        cap.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
        cap.setCapability(MobileCapabilityType.TAKES_SCREENSHOT, true);
        cap.setCapability(AndroidMobileCapabilityType.DEVICE_READY_TIMEOUT, 60);
        driver2 = new RemoteWebDriver(new URL("http://10.100.225.196:5008/wd/hub"), cap);

Second android device

@BeforeMethod
    public void setup() throws Exception, IOException, MalformedURLException {

        ServerArguments serverArguments = new ServerArguments();
        serverArguments.setArgument("--address", "10.100.225.196");
        serverArguments.setArgument("--local-timezone", true);
        serverArguments.setArgument("--port", "4723");
        serverArguments.setArgument("--session-override", true);
        AppiumServer appiumserver = new AppiumServer(serverArguments);
        if (appiumserver.isServerRunning()){
            appiumserver.stopServer();
        }
        appiumserver.startServer();
        if (appiumserver.isServerRunning()){
            System.out.println("Appium server for Galaxy Tab4 has been started successfully" );
            }else {
                System.out.println("Appium server for Galaxy Tab4 has not been started successfully" );
            }
        Thread.sleep(10000);
        DesiredCapabilities cap = new DesiredCapabilities();
        cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
        cap.setCapability(MobileCapabilityType.DEVICE_NAME, "GalaxyTab4");
        cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
        cap.setCapability("--udid", "d66f5f10");
        cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1.1");
        cap.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
        cap.setCapability(MobileCapabilityType.TAKES_SCREENSHOT, true);
        cap.setCapability(AndroidMobileCapabilityType.DEVICE_READY_TIMEOUT, 60);
        driver = new RemoteWebDriver(new URL("http://10.100.225.196:4723/wd/hub"), cap);

As I explained earlier, the problem is that testNG.xml runs both smoke tests on only one device instead of doing parallel on both devices simultaneously. Please give me a hint if something is wrong.

Upvotes: 3

Views: 1102

Answers (1)

Sadik Ali
Sadik Ali

Reputation: 1205

You should also run Appium server with different bootstrap by adding one more server argument:

serverArguments.setArgument("--bp", "78653");

Server flags click

more details go though below link: Click

Upvotes: 1

Related Questions