Appium Test Execution on a Remote Device
Frank Moyer
Mobile test automation teams often face the challenge of orchestrating test executions when device capacity runs out. A common question arises: Should the device lab platform itself queue up incoming test requests until a device is available, or should such logic be handled at the CI/CD or automation framework level?
In this post, we’ll explore the concept of device queuing, discuss why Kobiton (and other platforms) may prefer not to provide an enforced queue, how Kobiton’s Device Reservation feature offers an alternative, and show you how to implement an effective polling strategy in your CI/CD pipelines—complete with code snippets for GitLab CI.
Device Queuing is a mechanism by which test sessions that exceed the current device capacity are placed in a waiting line until a device becomes free. When all devices are busy:
While a built-in queue sounds convenient, it can come with downsides, including hidden timeouts, unintended bottlenecks, and reduced flexibility to prioritize or reroute tests.
Although automatic queuing is useful in some scenarios, it can introduce complexities:
Kobiton’s philosophy is to give you full control over how your tests are queued and retried:
While Kobiton does not implement a first-in, first-out queue for devices, it does provide a Device Reservation feature that allows you to reserve specific devices in advance. This can be particularly beneficial for critical or high-priority test suites that must have guaranteed access to a device at a specific time.
Important Note: Reserved devices that are left idle mean fewer devices are available to the general pool. Striking a balance between reserved and non-reserved devices is key to avoiding overall device underutilization.
Even with Device Reservation, you may still need to handle concurrency for non-reserved devices. Below is the general approach for setting up CI/CD-level polling:
Note: Replace “<BASE64_ENCODED_CREDS>” with your actual Kobiton authorization header (Basic Auth token) or whatever credentials your organization uses.
5.1 GitLab CI/CD Example
stages:
- check_devices
- run_tests
check_devices:
stage: check_devices
image: alpine:3.16
script:
- apk add --no-cache curl jq
- |
max_retries=5
wait_interval=30
device_available=false
for i in $(seq 1 $max_retries); do
available_count=$(curl -s -X GET "https://api.kobiton.com/v1/devices" \
-H "Authorization: Basic <BASE64_ENCODED_CREDS>" \
| jq '[.devices[] | select(.isAvailable == true)] | length')
if [ "$available_count" -gt 0 ]; then
echo "Device is available."
device_available=true
break
else
echo "No available device. Retrying in $wait_interval seconds..."
sleep $wait_interval
fi
done
if [ "$device_available" = false ]; then
echo "No device became available after $max_retries retries."
exit 1
run_tests:
stage: run_tests
script:
- echo "Running tests..."
- # e.g., "mvn test"
While these examples illustrate a straightforward polling mechanism, you can adapt them to better suit your organization:
Platform-level device queuing might sound attractive, but it can bring rigid timeouts, hidden bottlenecks, and reduced flexibility. Implementing CI/CD-level queuing or polling for mobile test automation places you in full control—letting you tailor the concurrency logic to your unique workflow and keep an eye on performance bottlenecks directly in your pipelines.
By leveraging Kobiton’s API alongside features like Device Reservation and your existing CI/CD pipeline, you can seamlessly manage when and how to run tests. The result is a more optimized automation flow, reduced risk of contention for devices, and confidence that critical tests will always have a device ready when they need it. Give Kobiton a try today!