Dockerizing appium tests


#1

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


Running appium fram work on docker
#2

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???


#3

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.


#4

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???

#5

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


#6

switching to vagrant, I’ll update once done.


#7

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


#8

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.


#9

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


#10

Ok, I will update that.


#11

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.


#12

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.


#13

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.


#14

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.


#15

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?


#16

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


#17

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


#18

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.


#19

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


#20

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’