Dockerizing appium tests

Hello everyone,

I have written a simple tutorial explaining how you can dockerize appium tests with a demo app. You can check it at https://github.com/vbanthia/appium-docker-test/blob/master/README.md.

I am currently using it for my personal projects, so thought it will great to share this knowledge. Feel free to ask any question.

Cheers,
Vishal

4 Likes

Hey @banthia
It seems that you are using ubuntu(linux) and able to mount the device. Iā€™m trying to achieve same over mac osx.
Have done this with mac???

Yeah, I was using OS X. You will have to add USB Filters in order to access devices from VM. I have written instructions to add UsbFilters here. https://github.com/vbanthia/appium-docker-test/blob/master/docs/EASY_SETUP.md#mac-osx

In case, you are not using Vagrant and using Virtual Box directly, You can refer Virtual Box documentation.
https://www.virtualbox.org/manual/ch03.html#idp46608643879360

Let me know, if you have any problem.

Thanks Vishal,
Iā€™m working with OSX 10.10.5 and I think iā€™m getting closer, here are my steps.

  1. Start the docker from ā€œDocker quick start terminalā€
  2. Start the Virtual box GUI application.(If i fire ā€œadb devicesā€ from host terminal i can see the devices)
  3. Go to settings in the VBox of running default container and an empty filter for usb and click ok. Then disconnect the device and reconnect. (if i fire ā€œadb devicesā€ on host it does not displays the device) :+1:

4.Go to VBox GUI and click on show button

So we have mounted the usb device on the Guest. :+1:

5.Now run the container with below command
docker run -d --privileged -v /dev/bus/usb:/dev/bus/usb --name adbd sorccu/adb

6.Now run below command to execute the adb devices over the detached container
docker run --rm -ti --net container:adbd sorccu/adb adb devices

It does not shows any devices

List of devices attached```


P.S. I'm just trying to figure out if i'm following all the steps correctly. Container i'm using is [here](https://github.com/sorccu/docker-adb)
Is there anything i'm missing here???

Oh, so you are using Dockerā€™s tool box for OS X.

Personally, I have never used it and I am not a big fan of it. I can only guess what may be causing problem in your environment. It may be because you are adding filters after VM is already booted. I think Virtual Box need this information(Usb Filters) at the time of booting so that it can mount hostā€™s device drive. I donā€™t think it can mount it after boot is already completed.

I will suggest you to use vagrant to create a new VM and run docker containers. This will give you more flexibility to control VM environment and adding filters before boot. You can also use the Vagrantfile provided by me in the repository. That Vagrantfile also install docker.

Steps will be

  1. Install vagrant for Mac OSX
  2. Clone the repository
  3. Update Vagrantfile according to your filters
  4. Run vagrant up
  5. Run ā€˜vagrant sshā€™

Now, you will be inside VM.
6. You can run any docker command in VM, since docker is already installed and running in background.
7. You can check if device is mounted by running sorccu/adb container

switching to vagrant, Iā€™ll update once done.

@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ā€™