Executing Robot test cases in parallel on 2 Android devices through Appium

First thing to know about this is that Robot doesn’t support or there is nothing built-in to execute parallel execution of test cases on multiple machines or devices.

But we are Engineers, we will hack it up.

How did we do it?

Use Selenium Grid to run couple of appium node instance, then run equal number of pybot instance to call the same test cases to execute it on 2 different device, that’s it you are done.

 

Confused!!! If yes,  just ignore the earlier sentence. Let’s break it up a bit.

 

Step 1

Have couple of Android device or virtual device connected to a server, where you will be running the Selenium server.

Step 2: Selenium Grid – Starting the Hub.

What is Selenium Grid?
Mainly used during Selenium automation, allows to run run tests on different machines against different browsers in parallel. More details in the below link.
Why do I need this?
Just stay with me for now. Will be clearer as we proceed.
If you have read & understood everything in the above link, then we would need to start the selenium hub.
Download the Selenium jar from the below link.

Start the Hub, you would need java installed for this.

java -jar selenium-server-standalone-3.4.0.jar -role hub
The above needs to be run as a background process whether you are running it on linux or windows.

Step 3: Selenium Grid – Starting the Mobile nodes

More details on Appium Grid would be available here.
I got 2 Android devices, one is a LYF & other is a Lenovo mobile.
Find the id of the connected mobile device using the command
adb devices
Now you need 2 config files in json format for both these devices. Attaching the same here.
node.lyf.js
{
    "capabilities": [
        {
            "applicationName": "LYF",
            "deviceName" : "fd1bee6e",
            "browserName": "LYF",
            "platformName": "ANDROID",
            "maxInstances": 1
        }
    ],
    "configuration": {
        "cleanUpCycle": 2000,
        "timeout": 30000,
        "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
        "host": "127.0.0.1",
        "port": 4723,
        "bootstrap-port":  4724,
        "maxSession": 1,
        "register": true,
        "registerCycle": 5000,
        "hubPort": 4444,
        "hubHost": "192.168.1.101",
        "udid":  "fd1bee6e"
    }
}
node.lenovo.js
{
    "capabilities": [
        {
            "applicationName": "LENOVO",
            "deviceName" : "4050dac6",
            "browserName": "LENOVO",
            "platformName": "ANDROID",
            "maxInstances": 1
        }
    ],
    "configuration": {
        "cleanUpCycle": 2000,
        "timeout": 30000,
        "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
        "host": "127.0.0.1",
        "port": 4730,
        "bootstrap-port":  4731,
        "maxSession": 1,
        "register": true,
        "registerCycle": 5000,
        "hubPort": 4444,
        "hubHost": "192.168.2.77",
        "udid":  "4050dac6"
    }
}

Some of the things to note.

 

udid – Unique device identifier of the connected physical device. This should be available from the ‘adb devices’ output.

hubHost – Selenium host IP where the selenium java jar is run.

hubPort – The default port the hub uses to listen for new requests is port 4444

port – port to listen on. Should be unique for both the devices.

bootstrap-port – (Android-only) port to use on device to talk to Appium

 

If you have got this setting done & saved this in a file. Then start the nodes.

appium --nodeconfig node.lyf.js -p 4723 -bp 4724

appium --nodeconfig node.lenovo.js -p 4730 -bp 4731

 

Now the nodes would register with the hub. You should see this log in the selenium hub.

 

23:18:23.549 INFO - Nodes should register to http://192.168.1.101:4444/grid/register/
23:18:23.549 INFO - Selenium Grid hub is up and running
23:23:07.350 INFO - Registered a node http://0.0.0.0:4723
23:23:24.929 INFO - Registered a node http://0.0.0.0:4730

Step 4: Build a test script

The test case is to open a calculator & does some simple operations.
*** Settings ***
Library            AppiumLibrary
Documentation    demo for appium library
Force Tags       demo

*** Variables ***
${node}      lyf

*** Test Cases ***
test_demo
    [Tags]

    Run Keyword If      '${node}'=='lyf'        Open Application  http://localhost:4444/wd/hub  platformName=Android  platformVersion=6.0.1  deviceName=fd1bee6e  app=com.android.calculator2  automationName=appium  appPackage=com.android.calculator2  appActivity=com.android.calculator2.Calculator
     Run Keyword If      '${node}'=='lenovo'        Open Application  http://localhost:4444/wd/hub  platformName=Android  platformVersion=6.0.1  deviceName=4050dac6  app=com.google.android.calculator     automationName=appium     appPackage=com.google.android.calculator      appActivity=com.android.calculator2.Calculator  
    Click ELement      id=digit_9
    sleep     3
    Click ELement      id=op_mul
    sleep     5
    Click Element      id=digit_9
    sleep     5
    Close All Applications
${node} – Variable to identify as to which command should be executed.
http://localhost:4444/wd/hub – Selenium hub needs to be called.
platformVersion – Mobile device android version.
deviceName – the name you got from the above ‘adb devices’ output.
app – The app name you get after executing the command ‘adb shell pm list packages -f’. In this example we are choosing the default browser app for testing.
appPackage – Will write a separate blog to find the package name
appActivity – Will write a separate blog to find the Activity name.

Step 5:  How to run the test case parallelly on both the devices?

From cli, go to the directory where you have saved your test case file.

Then execute the following commands.

pybot --variable node:lyf  -d /Users/shivaram/projects/lyf/  test_andoid_app.txt
pybot --variable node:lenovo  -d /Users/shivaram/projects/lenovo/  test_andoid_app.txt

–variable parameter is used to choose which line to be executed in the script.

-d – This is very important, this specifies as to where to create output files. The default is the directory where tests are run. It is good you specify the directory otherwise as you are running the pybot command twice, the output files may be overwritten & test cases may fail.

test_android_app.txt is the test case file.

 

Enjoy!!!!!

Hi there. I'm Shivaram. Security & Network Professional with around 10+ years of experience. Here on this blog to share all my testing related experience. I'm a problem solver & key to that is to come up with the right questions. Of course we then have Google for all the answers.

4 thoughts on “Executing Robot test cases in parallel on 2 Android devices through Appium

Leave a Reply to Shivaram Subramanya Cancel reply