Dockerizing appium tests

@banthia Thanks for the suggesting Vagrant i’m now able to mount the usb devices on docker container.
I’ll start using your container and let you know things i get.

My repo if anyone wanna try.

Good!

One more thing, in your step 6, you are disconnecting and reconnecting the device. I don’t think it is necessary. You will be still able to mount device without reconnecting.

Hello guys,

I do not know much about docker, but i have couple of questions. So please help me to understand purpose of containarizing appium.

  1. Since everything you can setup using shell script also, then why do you need to write docker file? In our case android-sdk / Xcode which huge download, do you think isn’t it bad idea to include such huge download in docker file? – i believe docker is good for quick setup for development purpose but it is not good for testing that i believe.
  2. How to expose USB port to docker container?
  3. I doubt docker will work with emulator also?
  4. I have Xcode and Android-sdk to my host machine, so is there anyway to share those to my docker container?

Thanks,
Priyank Shah

Ok, I will update that.

Well, if you read the tutorial thoroughly, you will get all your answers. I will try to summarise all the benefits again here.

Docker itself is a big topic, I cannot explain everything about it here. The problem which docker solves in case of appium or other selenium based test is parallelisation. As you may have also noticed while working with appium, that mobile testing is too slow compare to browser testing. The only way, you can make it fast is by parallelisation, that is why selenium community developed selenium grid.

Without docker, if you try to run your test parallel, you will need to start n number of appium server on different ports, you will also have to set different bootstrap ports, chromedriver ports etc etc. And then start appium driver on corresponding server ports. In case, if you want to scale your run environment i.e, machines running appium test then you will have to provision all those machine with appium dependencies i.e, android-sdks, nodejs etc etc. This is just pain. Nobody wants to work like this and this is one of the main reason for developers getting demotivated easily and ending up not writing tests at all.

If you dockerize your tests, you don’t need to think about run environment. You don’t need to think about what nodejs version, android sdk version is installed. Actually, you don’t need to install them at all. All you need to do is install docker which is so easy.

You can maintain all your test dependencies and run environment in a single file i.e, Dockerfile. Rest, everything will be taken care by docker. You can run as many containers in single machine i.e, as many parallel tests in single host machine without any special requirement.

This is why you should consider dockerizing your tests.

About Xcode and stuff, I will say, currently you cannot run iOS test in docker container as OS X does not support docker natively. You can only run android tests in docker container till Apple starts supporting docker which I am not sure gonna happen soon.

About exposing USB devices to docker container, it is explained in the tutorial, let me know if you still find difficulties in setup.

About running emulator in docker container, well theoretically it is possible. I have not tried it yet, and I am not very much motivated to this now. If you do so, it will be cool and useful.

Reason why I am not interested in emulator is because I have my own android device farm setup. I setup my device farm using this tool https://github.com/openstf/stf.

In my own personal setup, I use Jenkins for CI. Docker for run envrironment and Openstf for managing real devices.

3 Likes

As Vishal said Docker is very vast thing. When i started exploring it was just out of curiosity while looking into CI stuffs.

Answer to your question-
1.Docker is not an ordinary Virtual machine. There more to it, for basic explanation you can look here

2.Tinkering over native docker installation to mount USB device did not work for me, so i used it with vagrant and it worked.
What i did is mount the usb device on vagrant box, and inside that again mount it to docker container.(seem complicated at first but once it works it’s awesome)

3.I’m sure it can run emulator(s) unless you hit the resource limit, here it’s running eclipse inside a container . And all you need is RDP, So you are not working in a headless environment as i initially thought dokcer is.

4.[quote=“banthia, post:11, topic:7664”]
About Xcode and stuff, I will say, currently you cannot run iOS test in docker container as OS X does not support docker natively. You can only run android tests in docker container till Apple starts supporting docker which I am not sure gonna happen soon.
[/quote] So here vagrant can help somewhat as i have posted here(+ legality issue)

@banthia Thanks for the openstf link, wasn’t aware of that. I’ll work with that instead of emulators.

3.I’m sure it can run emulator(s) unless you hit the resource limit, here1 it’s running eclipse inside a container . And all you need is RDP, So you are not working in a headless environment as i initially thought dokcer is.

Docker’s main use is pretty much similar to a barebones Linux server, although I suppose one could build a base image from a full blown Linux install that contains a GUI desktop. In essence, it is headless as you can’t access the “head/desktop” as a GUI other than a terminal session. But you can redirect UI-based output via x11 and that is what allows passing along the UI of Linux apps to the docker host/client to render it. The Linux apps themselves (i.e. emulator/simulator) need to support routing it’s graphical output to x11. You then use docker client connection with x11 enabled forwarding the docker guest (the container) x11 to the client/host’s x11.

That might get more complicated when you connect to a docker container remotely (e.g. user/client is not on the host that runs the docker containers). Easier to conceptualized when it’s all local (client, host, container all on same machine).

To set up Android emulator for docker, one probably would search for something like “Android emulator x11” and then apply that to docker setup following the example from pr4bh4sh’s link to docker-eclipse, if there isn’t already an Android emulator docker container project in existence - looks like there’s already some:

4.I have Xcode and Android-sdk to my host machine, so is there anyway to share those to my docker container?

Docker allows sharing “files”. So if all you need are just binaries and files, then that works if you mount the file locations on host as a volume on the docker containers. But if you need to set up stuff like environment variables and other stuff, that needs to be done on each container separately. This works best for sharing standalone apps/binaries but not stuff that needs “setup”. And this won’t work for Xcode since there is no docker Mac container support.

Hi
I am new to appium testing . I have some doubts , please help me out.

Can I install mac os yosemite on virtual box in windows pc. And what are pre conditions to be taken while installing mac on virtual box for running appium tests both on emulators and physical devices.

Kindly give the reply.

Interesting. We are also working on setting up a device farm in our organization. Could you please share me your experience on setting up device farm?

Hello banthia, do you have something similar but with appium java client and maven instead of Ruby and Rake? or could you give any hints how to implement this? Best

What will be the teng.xml content and the loading the capabilities and running the tests

could you please provide the steps (full description). I am trying to set up since 4 days. Not getting the complete picture.

secound thing is which image you pulled for appium. and how to set up the container.

At which point you are stuck. Did you follow the steps mentioned at https://github.com/pr4bh4sh/adb-on-docker

I have followed the below steps but while running the code i got this error

https://hub.docker.com/r/rgonalo/appium/

Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: ‘2.53.0’, revision: ‘35ae25b1534ae328c771e0856c93e187490ca824’, time: ‘2016-03-15 10:43:46’

Please reply its is very important for me

docker@boot2docker:~$ docker run --rm -ti --net container:adbd sorccu/adb adb devices
List of devices attached
ZY2232TB7B device

I have connected two devices. but it is showing only one

@banthia can you please clarify below

  1. “…The only way to reduce run time is by parallelisation…” , does this mean each container run tests on individual emulator or physical device ?

  2. If I’ve 10 android devices , how do I allocate each to individual container ?

  3. I’m using Docker technology to run web automation in parallel with help of selenium grid. One container works as Hub and others are node.

  4. Does this project also uses similar technique ?

Thanks in advance.

Regards,
Vikram

I have a docker container on azure cloud with appium, and My Device is not displayed.
Steps to reproduce:

  1. Run docker with " docker run -d --privileged -v /dev/bus/usb:/dev/bus/usb -p 4723:4723 -it appium/appium-docker-android bash "
  2. Then i input, " docker exec “docker container number” adb devices "
  3. I then get List of devices attached
  • daemon not running. starting it now on port 5037 *
  • daemon started successfully *
  1. Then i input, " docker exec “docker container number” adb devices "
  2. I get List of devices attached but its BLANK.

What do i need to do in order for my devices to be displayed when i run " docker exec “docker container number” adb devices "??? I’ve also tried adb connect 11.11.11.11:5555 and the request times out
Please Help @banthia

1 Like

Hi @banthia

I am using windows 7.I have automated simple app with appium.Can i implement the same using docker? i have installed docker using docker tool box.

Can you help me to proceed further?

Could Docker run Appium tests without emulators?

If so, I’m interested to hear solutions. My job won’t allow me to download HAXM for Android Emulators.