Single Appium server to handle tests to multiple Android instances in parallel
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?
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.
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
Most likely both sessions will fail
Any reason to not use Selenium Grid for this? You can then automate the capabilities generation and manage the ports through it.
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?
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.
With Selenium grid you will still need Appium server with each device. It does not solve original question.