appium icon indicating copy to clipboard operation
appium copied to clipboard

Single Appium server to handle tests to multiple Android instances in parallel

Open pkill37 opened this issue 6 years ago • 7 comments

I have many Android containers running in the cloud which I want to control remotely, in parallel, through Appium. However it's not obvious how I can use a single Appium server (which can easily be scaled later on) to route commands through to an individual Android instance.

Right now I have a Docker image with ADB and Appium installed which basically (1) connects to the ADB daemon on the Android container and (2) launch the Appium server

#!/bin/sh
adb connect "$1"
appium

Then I launch one of these Docker containers per each Android instance that I want to control. But this is not very easy to scale and there is still a lot of work in managing used ports (when port forwarding Appium's 4723 port to a unique port for each Android instance).

What is the canonical way to do this in the Appium ecosystem?

pkill37 avatar Jun 23 '20 13:06 pkill37

It will anyway be necessary to manage ports/devices acquisition. A testing session will be just using the particular device udid, that is passed to it. It does not care whether this device is already used by other instances.

mykola-mokhnach avatar Jun 23 '20 13:06 mykola-mokhnach

What happens if I have two Docker containers connecting to the same Android instance and I start sending Appium commands to it?

#!/bin/sh
adb connect 1.2.3.4:5559
appium

pkill37 avatar Jun 23 '20 14:06 pkill37

Most likely both sessions will fail

mykola-mokhnach avatar Jun 24 '20 07:06 mykola-mokhnach

Any reason to not use Selenium Grid for this? You can then automate the capabilities generation and manage the ports through it.

simoreira avatar Jun 29 '20 15:06 simoreira

I didn't look into it before but it might be useful and maaaaybe it fits my use case.

Essentially I am dynamically starting instances of Android in the cloud, at any point many of these instances can be started or stopped. Immediately after one is started I want to control it remotely, which Appium (more typically used for testing) could be used for.

A key point here is the number of instances is always changing, when they are stopped they are no longer relevant and new ones will be started afterwards.

As I understand it, Selenium Grid needs to be provided a capabilities list beforehand in the configuration, no? But in my case devices come and go so maybe it doesn't quite work for m? Or is there a nice way to handle this dynamic capabilities list?

pkill37 avatar Jun 30 '20 08:06 pkill37

Are you able to retrieve the details of your Android instances on the go? Specifically which devices are up and their details (device name, OS version)? I think that if you are able to get this you'll be good to go to generate the capabilities list dynamically since most configurations are static. You could have a script that detects the available instances and generates configs for them, then you just need to register them on the grid:

appium -p 1234 --nodeconfig node.json

When you have selenium hub up and running you have to register each node you want to use in the server. When a node is connected it keeps polling the hub in order to show itself as available. As far as I know, in the default configuration, when a node does not poll the hub, the server waits for its connection to be available again. However, although I haven't looked this up, I would say there is a way to change this behavior and just close the connection when a device does not respond. With this, your dead instances can be easily ignored by the grid.

simoreira avatar Jun 30 '20 10:06 simoreira

With Selenium grid you will still need Appium server with each device. It does not solve original question.

amedvedjev avatar Jul 03 '20 05:07 amedvedjev