vbanthia-zz / appium-docker-demo

Appium sample test running on real devices inside docker container
MIT License
87 stars 23 forks source link

Container grabs all of the connected devices #5

Closed argeas closed 7 years ago

argeas commented 7 years ago

there is na issue regarding running more than 1 device. E.g. I have 2 devices and start one container. then I start another container. running adb devices on the first container shows the devices. running adb devices on the second doesnt show anything. If I unplug and replug one device it is then seen by the second container. ( 1 on each container when running adb devices )

argeas commented 7 years ago

Found a solution : lsusb to show devices. then I run container using the following to allocate specific device per container :

docker run -d -t -i --device=/dev/bus/usb/001/003 --name s3 appium/test1:latest

Were the first number, the Bus, is 001. The second number, the Device, is 003.

bash-4.4# lsusb Bus 001 Device 003: ID 04e8:6860

vbanthia-zz commented 7 years ago

Great.

satishtv commented 7 years ago

How to get Bus and Device number. Do you refer device ID as device number?

argeas commented 7 years ago

when you run lsusb in the terminal window you get a list of connected devices in the format: Bus 020 Device 013: ID 1004:61f9 LG Electronics Inc. LGE Android Phone Serial: 02e85ac75cc8cf82

Where in this case ID is the USB Hardware vendor id, BUS is the usb bus asssigned to the device and Device is the USB port assigned to the device. Note: in the case of 2 nexus5 (or LG, Sony etc.. ) devices the ID will be the same since they have the same hardware

The only way to match the desired device with the desired usb bus and device is greping the the serial of the device and extracting the respective usb bus and Device (port) from the printed line of the terminal.

This can be done with a simple bash script line. e.g

lsusb | grep 02e85ac75cc8cf82 | awk '{print $2"/"$4}' | sed 's/:$//'

you will have to edit it a bit to make it work for you

vbanthia-zz commented 7 years ago

One other approach to do is by setting up a small device farm using OpenSTF. OpenSTF provides API to connect remote device. So, inside the docker before running the appium server you can call OpenSTF API to reserve the device and then run automation on it.

Here is a simple example to show how to use OpenSTF API https://github.com/openstf/stf-appium-example

satishtv commented 7 years ago

Thanks @argeas @vbanthia Let me try both approaches.

satishtv commented 7 years ago

@argeas @vbanthia I have tried the below steps and got error as : docker: Error response from daemon: driver failed programming external connectivity on endpoint container-appium-one (29bcfef1a27c5cf23e2c028ae3727c26b366bb9f6e32c73a1cd5fd3aa30106b6): Bind for 0.0.0.0:4723 failed: port is already allocated. Steps followed:

  1. Started docker machine
  2. ssh into the machine
  3. Started first container "docker run --privileged -d -p 4723:4723 -v /dev/bus/usb/020/003:/dev/bus/usb/020/003 --name container-appium appium/appium"
  4. Then tried to start another container for the second device using command "docker run --privileged -d -p 4723:4723 -v /dev/bus/usb/020/004:/dev/bus/usb/020/004 --name container-appium-one appium/appium" and got the error as mentioned.