Selenium Grid 4 with Appium Devices

How to create a Selenium grid on version 4 including Appium controlled devices.

Tim Nederhoff
Test Automation Pro
3 min readOct 22, 2022

--

Selenium Grid 4 controlling Appium node

Selenium version: 4.5.0
Node version: 16
Appium version: 1.22.3
Android Emulator: 31.3.12
Android Command-line Tools: 8512546
Android SDK Manager: 7.0

This tutorial describes how to setup a Selenium grid in the latest version (4) combining mobile devices (usb connected or emulated devices). It is required that you have Java JDK installed on all machines, and Node/npm installed on the appium machine.

Install Android Tools

To have a virtual device working using the Android emulator, some tools have to be installed:

  1. download commandline tools (for sdkmanager): (link) and unzip in e.g. /opt/android
  2. rename the extracted folder from cmdline-tools to latest
  3. create a new directory in /opt/android called cmdline-toolsand copy the latest directory into it
  4. set ANDROID_HOME to /opt/android in .bash_profile or .zshrc:
    export ANDROID_HOME=/opt/android
  5. set tools in PATH variable: $ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/emulator:$ANDROID_HOME/platform-tools
  6. install emulator and platform tools (for adb and avdmanager): sdkmanager --install "emulator" "platform-tools"

Create Virtual Device

A virtual device can be created using an Android system image. To get an Android system image, use sdkmanger to download: sdkmanager --install "system-images;android-31;google_apis;x86_64". Assure that the architecture of the image matches the OS architecture.

Create a virtual device using avdmanager: avdmanager create avd --name "my-virtual-phone", --package "system-images;android-31;google_apis;x86_64" --device "Nexus 10" to use the device hardware profile of the Nexus 10. If no device is specified, you will be asked like 122 questions about the hardware specifications you want to use.

Run Virtual Device on the Emulator

To run the created virtual device (avd), execute the emulator with the avd specified: emulator -avd my-virtual-phone

Install Appium

Today Appium headless/server is a Node application, it can be installed globally by this command: npm install -g appium. Once Appium is installed globally it can be executed from any location. In Selenium 4, we have to use a “relay” mode to specify the actual (Appium) node. So there is no need to configure Appium for devices, just run the server: appium. Don’t forget to specify the chromedriver if you’re using hybrid or browser apps. By default port 4723 is used, make sure that the server is accessible on the Appium port (configure the possible firewall accordingly).

Install Selenium Hub and Node

Download Selenium server on the projects Github page, choose the selenium-server-x.x.x.jar. First, the hub should be running, so start that one without required configuration: java -jar selenium-server-4.5.0.jar hub. Then the Selenium Node should be kicked off. This one needs a specific configuration to have Appium to work. The Selenium Node actually acts as a relay server, specifying the devices that Appium controls. So the usual capabilities normally set by Appium are now in the Selenium TOML configuration file, e.g.:

Then launch the Selenium Node: java -jar selenium-server-4.5.0.jar node http://mynodehost.com:4444 --config appium-config.toml. Now the node should be signed up on the Selenium Hub.

--

--

Tim Nederhoff
Test Automation Pro

As a Test Automation Engineer I help people in the testing field. Primarily by implementing test automation, CI/CD integration, tooling and testdata management