Run your Appium tests using Docker Android & Genymotion Cloud

Ellinor Kwok
Dec 19, 2018 · 5 min read
Image for post
Image for post

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

  • 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
- deviceis 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 device.json file.

Then, start the docker container with those commands :

$PWD : path where your device.json file is stored. For example, if you pulled the docker-android project, the path is
docker-android/genymotion/example/sample_devices

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:

  • 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 :

$PWD: path where your aws.json file is stored. For example, if you pulled the docker-android project, the path is
docker-android/genymotion/example/sample_devices

$PATH_AWS : path where your aws access keys are stored (e.g ~/.aws/ if you already have AWS CLI installed).

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:

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 :

$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.

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

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

Genymobile

We help enterprises build their future with Android We’re…

Ellinor Kwok

Written by

Presales, Technical Partnership Manager at Genymobile

Genymobile

We help enterprises build their future with Android We’re the team behind @Genymotion, the most complete Android emulation platform. Now available in the cloud with powerful testing and collaboration capabilities 💪☁️ ️More at genymotion.com/cloud

Ellinor Kwok

Written by

Presales, Technical Partnership Manager at Genymobile

Genymobile

We help enterprises build their future with Android We’re the team behind @Genymotion, the most complete Android emulation platform. Now available in the cloud with powerful testing and collaboration capabilities 💪☁️ ️More at genymotion.com/cloud

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store