How to run parallel tests with Appium on Android using Genymotion Cloud PaaS (AWS, GCP, ALIBABA)

Thomas CARPENTIER
Genymobile
Published in
3 min readDec 10, 2018

In my last story, I’ve explained how to run parallel tests with Appium on Android using Genymotion Cloud SaaS. Lots of our users saw this article and asked us how to do the same thing using Genymotion Cloud PaaS.

As a reminder, Genymotion provides Android emulators running as virtual images on AWS, GCP or Alibaba Cloud

Launch several devices

AWS, GCP and Alibaba Cloud provide a console for users to start and configure instances easily.

We have described all actions in specific user guide. Please refer to it to launch devices.

If you want to automate the start of the devices, you can refer to each providers specific APIs.

Connect devices through adb

To establish the communication between your computer or CI Server and Android virtual devices, follow the steps below:

1/ Using the old school method ( < Genymotion Cloud v5 0.)

1. Log in with SSH using

ssh -i key.pem shell@instance_ip

2. Enable ADB using

setprop persist.sys.usb.config adb
exit

When it’s done, you just have to connect your device using adb :

adb connect instance_ip

2/ Using the next generation API ( > Genymotion Cloud v6.0 )

We have developed an API to interact and configure a device. So now you can enable ADB using this simple API call :

curl -X POST "https://[instance_ip]/api/v1/configuration/adb" -H  "accept: application/json" -H  "Content-Type: application/json" -H  "Authorization: Basic [CREDENTIALS]" -d "{\"active\":true,\"active_on_reboot\":true}"

Note : CREDENTIALS is the value of `username:password` encoded in base64.

When it’s done, you just have to connect your device using adb :

adb connect instance_ip

❗️ Of course, you have to repeat these actions as many times as the number of running devices needed!

Start appium server

Since Appium 1.7, it’s easy to do parallel testing using only one appium server. Before that, we had to start N appium servers in order to test N devices in parallel.

So let’s start an Appium server, simply using the basic command:

appium

Write your tests in Python

(Again, we’ve used Python throughout this tutorial but you can use your desired language.)

We’ve chosen to use Pytest as our test framework. It has several useful plugins like:

  • xdist: for running tests in parallel.
  • rerunfailures: for rerunning failed tests an arbitrary number of times to reduce build failures due to flakey tests

Here is a simple python script, please replace `[instanceX_ip]` values by the IPs of your instances:

How to run Python tests in parallel

Now it’s time to run tests on all devices!

If we run the python script as follows:

pytest test_example.py

pytest will execute tests on one device at a time. This is not what we want. In order to have results as soon as possible, we need to execute all the tests at the same time. To do that, we can take advantage of the pytest-xdist plugin and run the following command :

pytest -n 3 test_example.py
  • -n : number of worker processes you want to use. Here we start the suite with 3 processes

That’s it! You’ve been able to run parallel tests on several Genymotion Cloud PaaS virtual devices using appium and pytest.

To learn more about Genymotion Cloud see the following resources :

To run parallelize your tests using Java rather than Python, see Ellinor Kwok project on Github.

--

--