Public | Automated Build

Last pushed: 2 years ago
Short Description
Short description is empty for this repo.
Full Description

docker-android-automator

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

Built with

  • latest debian
  • openjdk 7
  • Using the following docker images:
    • softsam/adb
    • softsam/android-*
    • softsam/appium
    • softsam/robotframework-appium

Prerequisites

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 volumes

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.

Running tests

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:

  • 16
  • 17
  • 18
  • 19
  • 21
  • 22

Note: you can run at the same time tests on the connected device and on emulators.

Emulators architectures

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:

Docker Pull Command
Owner
softsam

Comments (2)
myangelct1984
6 months ago

Status: Image is up to date for softsam/robotframework-appium:latest
[ ERROR ] Unexpected error: TypeError: descriptor 'lower' requires a 'unicode' object but received a 'str'
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/robot/utils/application.py", line 79, in _execute
rc = self.main(arguments, *options)
File "/usr/local/lib/python2.7/dist-packages/robot/run.py", line 429, in main
settings['WarnOnSkipped']).build(
datasources)
File "/usr/local/lib/python2.7/dist-packages/robot/running/builder.py", line 41, in build
return self._parse_and_build(paths[0])
File "/usr/local/lib/python2.7/dist-packages/robot/running/builder.py", line 48, in _parse_and_build
suite = self._build_suite(self._parse(path))
File "/usr/local/lib/python2.7/dist-packages/robot/running/builder.py", line 56, in _parse
warn_on_skipped=self.warn_on_skipped)
File "/usr/local/lib/python2.7/dist-packages/robot/parsing/model.py", line 42, in TestData
warn_on_skipped)
File "/usr/local/lib/python2.7/dist-packages/robot/parsing/model.py", line 209, in populate
warn_on_skipped, recurse)
File "/usr/local/lib/python2.7/dist-packages/robot/parsing/populators.py", line 110, in populate
init_file, children = self._get_children(path, include_suites)
File "/usr/local/lib/python2.7/dist-packages/robot/parsing/populators.py", line 162, in _get_children
for name, path in self._list_dir(dirpath):
File "/usr/local/lib/python2.7/dist-packages/robot/parsing/populators.py", line 177, in _listdir
for name in sorted(names, key=unicode.lower):
Starting: Intent { cmp=com.orange.androidlocales/.ChangeLocaleActivity
(has extras) }

myangelct1984
6 months ago

[ ERROR ] Unexpected error: TypeError: descriptor 'lower' requires a 'unicode' object but received a 'str'
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/robot/utils/application.py", line 79, in _execute
rc = self.main(arguments, *options)
File "/usr/local/lib/python2.7/dist-packages/robot/run.py", line 429, in main
settings['WarnOnSkipped']).build(
datasources)
File "/usr/local/lib/python2.7/dist-packages/robot/running/builder.py", line 41, in build
return self._parse_and_build(paths[0])
File "/usr/local/lib/python2.7/dist-packages/robot/running/builder.py", line 48, in _parse_and_build
suite = self._build_suite(self._parse(path))
File "/usr/local/lib/python2.7/dist-packages/robot/running/builder.py", line 56, in _parse
warn_on_skipped=self.warn_on_skipped)
File "/usr/local/lib/python2.7/dist-packages/robot/parsing/model.py", line 42, in TestData
warn_on_skipped)
File "/usr/local/lib/python2.7/dist-packages/robot/parsing/model.py", line 209, in populate
warn_on_skipped, recurse)
File "/usr/local/lib/python2.7/dist-packages/robot/parsing/populators.py", line 110, in populate
init_file, children = self._get_children(path, include_suites)
File "/usr/local/lib/python2.7/dist-packages/robot/parsing/populators.py", line 162, in _get_children
for name, path in self._list_dir(dirpath):
File "/usr/local/lib/python2.7/dist-packages/robot/parsing/populators.py", line 177, in _listdir
for name in sorted(names, key=unicode.lower):
Starting: Intent { cmp=com.orange.androidlocales/.ChangeLocaleActivity
(has extras) }