Appium Automation: Parallel Execution in Multiple Real Devices

Automation Test Script will be running in multiple devices simultaneously using the following jars; I have tried the below implementation in Windows x86 machine.

  1. Selenium Grid from Selenium Standalone server
  2. Appium node instance
  3. TestNG

If you want to test the mobile application in difference device simultaneously using the same script and single driver instance, please follow the below steps to implement at your end;

Download the Selenium Standalone Server from the below URL, which will be used to run the Selenium Grid; (I have downloaded the 3.0.0-beta2 version)

http://www.seleniumhq.org/download/

Start the Server based on the below command;

C:\Users\Gopikannan\Downloads>java -jar selenium-server-standalone-3.0.0-beta2.jar -role hub

You will get the server UP success message including the node server URL as like the below screenshot;

Grid_Success

Run the URL http://192.168.1.34:4444/ in your PC web browser and verify selenium grid is UP and successfully running in the machine.

Selenium Grid part got over and now coming to the Appium node server in which we are going to run multiple node instance respect to the device. In this session, I have taken two different real devices of One Plus 3 (A3003) and Sony Xperia XA (F3116) to test my script under parallel execution.

Download and Install Appium in you machine based on my old blog posting URL;

https://gopekannan.wordpress.com/2015/08/26/how-to-automate-android-mobile-application-using-appium/

You need to create json file based on the below information and this is the file is going to deal with the selenium grid server. Please find the below architecture diagram, which will explain about the flow in detail.

Architecture

Node Instance 1

I am creating a json file for the first instance and the One Plus 3 device as follows;

{

“capabilities”:

[

{

“deviceName”: “192.168.1.33:5757”,

“version”:”6.0.1″,

“maxInstances”: 3,

“platformName”:”ANDROID”

}

],

“configuration”:

{

“cleanUpCycle”:2000,

“timeout”:30000,

“hub”: “http://192.168.1.34:4444/grid/register/”,

“proxy”: “org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,

“url”:”http://192.168.1.34:4723/wd/hub”,

“host”: “192.168.1.34”,

“port”: 4723,

“maxSession”: 6,

“register”: true,

“registerCycle”: 5000,

“hubPort”: 4444,

“hubHost”: “192.168.1.34”,

“remoteHost”: “http://192.168.1.34:4723”,

“role”: “node”

}

}

Mobile device should be connected with the PC either in USB or wireless mode. Device name mentioned as device ip address and its assigned port address. If you are not familiar to assign a ip address and port number for a real device, please refer the below URL;

https://gopekannan.wordpress.com/2016/07/31/android-devices-wireless-connect-using-adb-android-debug-bridge/

If you are not in wireless LAN then you can use the device id in the device name instead of the device ip address and port number. You can get the device id information using the below command; Please note the same device information should be mentioned in the TestNG.XML suite file which will be explained in the later section.

adb devices

Now node server should be make it up using the below command, you should run the below command in the Appium installed location;

node.exe node_modules\appium\bin\appium.js –nodeconfig C:\Users\Gopikannan\Desktop\JSON\appium_node_oneplus.json -p 4723 -bp 2251 -U 192.168.1.33:5757

Node Instance 2 

You need to create another json file for the second instance and the Sony Xperia XA device as follows;

{

“capabilities”:

[

{

“deviceName”: “192.168.1.35:5656”,

“version”:”6.0.1″,

“maxInstances”: 3,

“platformName”:”ANDROID”

}

],

“configuration”:

{

“cleanUpCycle”:2000,

“timeout”:30000,

“hub”: “http://192.168.1.34:4444/grid/register/”,

“proxy”: “org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,

“url”:”http://192.168.1.34:4724/wd/hub”,

“host”: “192.168.1.34”,

“port”: 4724,

“maxSession”: 6,

“register”: true,

“registerCycle”: 5000,

“hubPort”: 4444,

“hubHost”: “192.168.1.34”,

“remoteHost”: “http://192.168.1.34:4724”,

“role”: “node”

}

}

Sony Xperia XA should be connected with the PC.

Now node server should be make it up using the below command, you should run the below command in the Appium installed location ny opening a another command prompt;

node.exe node_modules\appium\bin\appium.js –nodeconfig C:\Users\Gopikannan\Desktop\JSON\appium_node_sonyxa.json -p 4724 -bp 2252 -U 192.168.1.35:5656

You could see that two node registered with the Grid server based on the below screenshot;

node register

Selenium Grid Server and Appium Node instance got UP successfully.

Node success

Grid console

Environment part got over, now entering into the Test Suite Part and Test Script coding part to handle the parallel execution in multiple devices.Test Suite should be created in your java project file associated in the Eclipse IDE.

Create a TestNG specific test suite XML in your java project as follows;

<?xml version=“1.0” encoding=“UTF-8”?>

<!DOCTYPE suite SYSTEM “http://testng.org/testng-1.0.dtd”&gt;

<!–  Specify the test suite name –>

<suite name=“DeviceSuite” annotations=“JDK” parallel=“tests”>

<test name=“Device 1”>

<parameter name=“port” value=“4723”>

</parameter>

<parameter name=“device” value=“192.168.1.33:5757”>

</parameter>

<classes>

<class name=“appiumdemo.AppiumTest”>

<methods>

<include name=“Login” />

</methods>

</class>

</classes>

</test>

<test name=“Device 2 Sony”>

<parameter name=“port” value=“4724”>

</parameter>

<parameter name=“device” value=“192.168.1.35:5656”>

</parameter>

<classes>

<class name=“appiumdemo.AppiumTest”>

<methods>

<include name=“Login” />

</methods>

</class>

</classes>

</test>

</suite>

Please don’t forget to mention the “package name”.”class name” in the class name attribute as specified above. If you are not in the WLAN, please mention the device ID(Example:b493juj23) in the device value section.

Now coming to the coding part in which port number and device information should be passed as parameters in the BeforeTest section; Parameters will be passed from the suite XML file to the setup method as specified below;

@BeforeTest

@Parameters({“port”,”device”})

public void setUp(String port, String device) throws Exception

{

DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability(CapabilityType.BROWSER_NAME, “”);

capabilities.setCapability(“deviceName”, device);

capabilities.setCapability(“platformVersion”, “6.0.1”);

capabilities.setCapability(“platformName”, “Android”);

capabilities.setCapability(“appPackage”, “com.attendify.confxvfnrl”);

capabilities.setCapability(“appActivity”, “com.attendify.android.app.activities.SplashActivity”);

try

{

driver = new RemoteWebDriver(new                      URL(“http://192.168.1.34:”+port+”/wd/hub&#8221;), capabilities);

driver.manage().timeouts().implicitlyWait(80,TimeUnit.SECONDS);

Thread.sleep(10000);

}

catch(MalformedURLException e)

{

e.printStackTrace();

}

}

A single driver instance will be utilized to run the script in multiple devices and you can select the test suite XML and run it in the Eclipse IDE. Your script will be running in the multiple devices simultaneously.

run_suite

Happy Coding!!! 🙂

One thought on “Appium Automation: Parallel Execution in Multiple Real Devices

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s