Run your Appium tests using Docker Android & Genymotion Cloud

Ellinor Kwok
Genymobile
Published in
5 min readDec 19, 2018

Last April, Genymotion team went to the Appium Conference in London and met Budi, open-source enthousiast, contributor to the Appium project on Github who did a talk on his Docker-Android project. We started working together on an integration of Genymotion Cloud.

In this article, we’ll explain what are the main advantages of using Docker-android with Genymotion Cloud to run Android mobile automated tests, then we will provide tutorials.

Genymotion Cloud hosts cloud-based Android emulators running in a SaaS fashion or as virtual images on AWS, GCP or Alibaba Cloud (PaaS). The integration so far has been done with SaaS & PaaS (only AWS).

Docker-Android is a docker image built to be used for everything related to Android mobile website or application testing. All the tools needed (devices, framework, Android SDK…) are packaged in the image. It is free and open source and supports other features such as video recording.

Advantages

The main goal is to help the user focus on writing the UI tests by leveraging the advantages of using a docker :

  • Having a ready to test infrastructure that will run the same environment everywhere it is deployed (your local machine, server) : You get rid of all the hassle of installing the tools needed (Appium, Selenium Grid, AWS CLIs, Android SDK, Genymotion tools…) but also maintaining them. For example if you update the version of one tool it could break the integration.
  • Being able to switch between cloud platforms easily : e.g. from Genymotion Cloud SaaS to AWS. All the integrations are done in one single docker container.
  • No knowledge is needed on how to use tools to start Genymotion devices in the cloud and integrate it with Appium and Selenium. All these mechanisms are done in the background, letting the users focus on writing their tests.

Tutorials

1/ Start the devices on which you wish to run your test on Genymotion Cloud

  • SaaS

First, you need to define the devices with a JSON file :

where
- template is the name of the template of the device you wish to start
- nameis the name of the device
- port (optional) is the adb port if you need a persistent one. This is indeed quite handy for running appium tests without changing the device name in your tests every time you need to run those tests.

You can refer to this saas.json file.

Then, start the docker container with those commands :

export USER="xxx"
export PASS="xxx"
docker run -d -p 4723:4723 -v ${PWD}/saas.json:/home/androidusr/genymotion_template/saas.json -e DEVICE_TYPE=geny_saas -e GENY_SAAS_USER=${USER} -e GENY_SAAS_PASS=${PASS} -e APPIUM=true --name android-container budtmo/docker-android:genymotion

$PWD : path where your saas.json file is stored

If you’d like to use appium with selenium hub, you can use docker-compose. Please refer to this geny.yml file. Then use this command to start the docker instead of docker run. Your current path must be
docker-android/genymotion/example:

export USER="xxx" && export PASS="xxx" && docker-compose -f geny.yml up -d
  • PaaS (AWS)

First, you need to define the devices with a JSON file :

You need to define for each instance the region (region field e.g eu-west-1 for Ireland) where it will run and the type of instance (instance field e.g t2.small).
Please refer to the product page for the complete list of compatible instance type.

By default, if you fill the android_version field (5.1 / 6.0 / 7.0 / 8.0), it will start the latest image available on the market. If you prefer to start preconfigured images you can use AMI field instead which is the AMI ID of the template.

Regarding security groups, if you don’t put any SG field, it will by default create one with those Inbound SSH, HTTP, HTTPS/WSS & WebRTC and Outbound rules on 0.0.0.0/0.

For a custom security group :

  • an existing one, put the group ID in the SG field, e.g "SG": "sg-12a28a6a"
  • non existing one, input blocks like this for inbound and outbound rules

You can refer to this aws.json file

Then start the docker container with this command :

export AWS_ACCESS_KEY_ID="xxx"
export AWS_SECRET_ACCESS_KEY="xxx"
docker run -it --rm -p 4723:4723 -v ${PWD}/example/genycloud/aws.json:/home/androidusr/genymotion_template/aws.json -e DEVICE_TYPE=geny_aws -e AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} -e GENY_SAAS_PASS=${AWS_SECRET_ACCESS_KEY} -e APPIUM=true budtmo/docker-android:genymotion

$PWD: path where your aws.json file is stored.

If you’d like to use appium with selenium hub, you can use docker-compose. Please refer to this geny.yml file. Then use this command to start the docker instead of docker run. Your current path must be
docker-android/genymotion/example:

docker-compose -f geny.yml up -d

2/ Run your appium tests

Once the docker container is started, devices are launched and connected to adb in the container with the appium server port 4723 or the selenium hub 4444 port exposed depending on which command you used to start the container. No further configurations is needed, just run your tests as usual.

These are the adb serials of the devices started to identify them (UDID DesiredCapability) on which your tests will run against :

  • SaaS
    If you defined the port e.g. 38727, the adb serial is localhost:38727 . If not it will be a random port.
  • PaaS
    Each device defined in the json file will get a port number starting from 5555. For example, if you start 2 devices, the adb serials will respectively be localhost:5555and localhost:5556 for the first and second device in the list.

If you want to verify the devices connected to adb, you can always run adb devices inside the container :

docker exec $ID adb devices

$ID is the ID of the container

You can refer to our previous blogpost (#SECTION Write your test in Python) or my project sample on Github in Java for more detailed information regarding the appium tests source code.

3/ Stop your devices

Once your tests are finished, stopping the docker will automatically stop the instances. You don’t need to tear them down manually.

docker stop $(docker ps -a -q)

We plan in the future to integrate with GCP & Alibaba Cloud. Please leave in the comments which one you would like first! :)

Thanks budi utomo for reviewing the article.

Sign up on Genymotion Cloud SaaS for a free trial

--

--

Ellinor Kwok
Genymobile

Presales, Technical Partnership Manager at Genymobile