Run Android tests on emulators, using appium and robot framework, in a single command line.
Using the docker in docker script made by @jpettazo (https://github.com/jpetazzo/dind).
- latest debian
- openjdk 7
- Using the following docker images:
Options and input / output
This container MUST be run with the --privileged option. This is needed since it will run other docker containers inside. It is also required to be able to access to physical devices plugged on USB ports.
You will also need to provide the apk of the application to test, and the tests to run (written with robot framework).
We recommand the following file structure:
/my_work_directory/automation /my_work_directory/automation/apk /my_work_directory/automation/apk/my_app_to_test.apk /my_work_directory/automation/robot # my robot framework tests
Output files will be written in the /my_work_directory/automation/output directory.
The image requires several volumes to be mounted in order to work.
The tests volumes
This volume is mandatory.
The /automation directory must contain the robot framework tests and the apk (see before).
The docker volume
This volume is mandatory.
You must mount the /var/lib/docker directory in /var/lib/docker, or the image will not work.
In order to run tests, you will have to specify if you wish to run them on physical devices, or emulators (or both).
All the example assume your automation directory is in your home directory (e.g. /home/myuser/automation).
Running the tests on physical devices
Run the following command:
docker run --privileged -v ~/automation:/automation -v /var/lib/docker:/var/lib/docker -v /dev/bus/usb:/dev/bus/usb softsam/android-automator -d
The tests will run on all the connected devices.
Note that you must mount the /dev/bus/usb directory so the docker container can access to your devices.
Running the tests on emulators
Specify the sdks of the emulators you wish to run the tests on, and the image will automatically run them for you.
Run the following command to execute your tests on APIs 17 and 21:
docker run --privileged -v ~/automation:/automation -v /var/lib/docker:/var/lib/docker softsam/android-automator -s 17,21
This will also generate a video of the test session in the output directory, along with the tests logs.
You can run tests on the following SDKs:
Note: you can run at the same time tests on the connected device and on emulators.
By default, emulators are run in arm. Since arm emulators are rather slow, you may prefer to use x86 images instead, to speed up your tests. Running x86 emulators requires your system to be able to run virtualization inside docker. To achieve this, your host will need to have kvm installed (not doable if you are running docker on MacOS or Windows, since boot2docker relies on Virtual Box, which does not support this feature).
If you are running on linux (or in VMWare), you can install the kvm packages, and start the android-automator container with 2 additionnal options:
- -v /dev/kvm:/dev/kvm
- --arch x86
This will run the emulators in x86, and should greatly improve their performances.
Here is the full command to run your tests with x86 emulators:
docker run --privileged -v ~/automation:/automation -v /dev/kvm:/dev/kvm -v /var/lib/docker:/var/lib/docker softsam/android-automator -s 17,21 --arch x86
Running the tests behind a proxy
Assuming your docker installation is properly configured, adding the http_proxy environment variable to the run docker command will to the job.
docker run --privileged -v ~/automation:/automation -v /var/lib/docker:/var/lib/docker -e http_proxy=http://proxy:8080 softsam/android-automator -s 22
Running tests in parallel
You may want to run tests in parallel to get a faster feedback. In order to achieve this, simply run the container several times, specifying a prefix (or else they will collide and no test will be run).
To run tests on SDKs 17 and 22 in parallel, run the following commands (in 2 shells):
docker run --privileged -v ~/automation:/automation -v /var/lib/docker:/var/lib/docker -e http_proxy=http://proxy:8080 softsam/android-automator -s 17 -p sdk17 docker run --privileged -v ~/automation:/automation -v /var/lib/docker:/var/lib/docker -e http_proxy=http://proxy:8080 softsam/android-automator -s 22 -p sdk22
Arguments passed to your robot framework tests
The robot framework tests are run using the pybot command. When run, the tests are given the following arguments (as variables):
- automator_android_api: the value of the SDK on which the test is run. You will need this since appium needs a different automation name depending on the SDK version (Selendroid if your API is lower than 17, Appium else).
- automator_locale: the locale of the device on which the tests runs.
Passing custom arguments to your robot framework tests
In some cases you need to pass your robot framework tests additional arguments, such as a platform, or any other environment data. The image allows you to provide the arguments you wish to pybot, using the -a (or --pybot-args) option.
For example, if you wish to specify some variable to your tests, you can do it by running the following command:
docker run --privileged -v ~/automation:/automation -v /var/lib/docker:/var/lib/docker softsam/android-automator -s 22 -a "--variable platform:dev"
Visualizing the tests in real time on an emulator
When running tests on an emulator, a video is recorded, but you can still see the tests in live, via VNC. Run the docker container with the -p 5900:5900 option:
docker run --privileged -p 5900:5900 -v ~/automation:/automation -v /var/lib/docker:/var/lib/docker softsam/android-automator -s 22
Displaying the help
The container has a minimal help wich may guide you through the different options you can pass to the image.
Run the following command:
docker run --privileged -v ~/automation:/automation -v /var/lib/docker:/var/lib/docker softsam/android-automator --help
You want more?
If this image does not provide the level of control you seek, take a look at the images it uses, they may save you some time.
This image heavily relies on the following images: