Monday, February 8, 2016

How to run two different application on two physical android devices in parallel?

Parallel execution of android applications have become a need now days given that number of test scenarios are higher. 

Parallel execution is done to achieve maximum test coverage with minimal time.

Appium provides a way for parallel execution.

To achieve this , we have to do the following steps.
  1. We need to start 2 appium instances on different ports.
  2. Boot strap port numbers for both the instances must be different.
  3. provide the unique identifier of physical devices using -U flag.
  4. If you are trying to run an Hybdrid application in parallel, make sure you start chrome driver on 2 different ports.


You can skip the point 4 if you are automating native android apps.

To start appium server you must have node.js installed or you can use default node executable residing inside appium installation directory.

1. Open a command prompt in admin mode and navigate till main.js file inside appium installation directory.

Main.js is find here: 

C:\Program Files (x86)\Appium\node_modules\appium\lib\server

2. run the below commands in different command prompt window. 

node main -p 4725 -bp 2293 -U place device 1 UDID--chromedriver-port 6000

node main -p 4724 -bp 2292 -U place device 2 UDID--chromedriver-port 6001

You will see appium server up and running on 2 different ports.


Instance 1

Instance 2


3. Now go to your testng.xml file and pass port number and device name as parameter from your testng.xml suite file.

Please make sure parallel attribute inside <suite> must be set to tests.


<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Preserve order test runs" parallel="tests">
   <test name="Test for account settings Mobile" preserve-order="true" >
        <parameter name="appName" value="accounts_582.apk" />
        <parameter name="deviceName" value="HTC Nexus 9" />   
        <parameter name="paramName" value="4724" />     
        <classes>
          <class name="omniauto.tests.Accounts_AndroidTest"></class> 
              <class name="omniauto.tests.AggregatedAccount_Settings"></class> 
              <class name="omniauto.tests.ManualAccountSettings_Test"></class> 
        </classes>
    </test>
    <test name="Test suite for account group setting Mobile" preserve-order="true" >
        <parameter name="appName" value="accountgroupsettings_582.apk" />
        <parameter name="deviceName" value="Samsung I9500 Galaxy S4" />
        <parameter name="paramName" value="4725" />
        <classes>
            <class name="omniauto.tests.Account_Group_Settings"></class>
        </classes>
    </test>
    
</suite>



4. Use that port number in forming your driver instance. 

driver = new AppiumDriver(new URL("http://127.0.0.1:"+portNum+"/wd/hub"), capabilities);

Happy learning ! :)

 

© 2014 DieHardTechy . All rights resevered. Designed by Diehardtechy