App & Browser Testing Made Easy

Give your users a seamless experience by testing on 3000+ real devices and browsers. Don't compromise with emulators and simulators

Home Guide How to set up your Appium Grid

How to set up your Appium Grid

By Garima Tiwari, Community Contributor -

Mobile App Testing ensures the delivery of mobile applications that serve, delight, and retain users through their high-end UX and cross platform compatibility. However, in the fast-growing digital market, users expect a new version of every app, laden with advanced features, every few weeks. To meet that demand, automation testing has become indispensable in software development pipelines. It has helped software development and testing professionals deliver high-end mobile apps within tight deadlines.

Like all aspects of development and testing, mobile testing requires the right tools and frameworks. Appium is one of the most widely used frameworks for automated mobile app testing of native and hybrid apps. It is built to facilitate fast and accurate results and thus is an important part of any mobile tester’s toolkit.

This article will explore how to set up Appium Grid to perform automated app testing.

What is Appium?

Appium is an open-source automation testing framework for apps supported by platforms like iOS, Android, macOS, and Windows. Similar to Selenium, it enables the tester to write test scripts in different programming languages such as JavaScript, Java, Ruby, Python, PHP, and C#, which can be used for both Android and iOS platforms.

What is Appium Grid?

Appium Grid is a proxy server that allows the tester to run parallel tests on multiple devices simultaneously. This is done by connecting the Appium Server with the Selenium Grid, which makes a hub with multiple nodes – each having a different device-browser combination to perform cross-platform testing. Hub and Nodes form the basic Appium Grid Structure, with the Hub serving as the central server entity, and Nodes being the individual devices on which the tests are run simultaneously.

Here, one server acts as the Hub, which accepts the access requests from the Webdriver Client. This is done by routing commands to remote web browser instances on each of the nodes.

The Hub conducts concurrent execution of tests on multiple machines, managing different browsers centrally, instead of conducting different tests for each of them. The Selenium Grid makes cross browser testing easy as a single test can be carried on multiple machines and browsers simultaneously. Naturally, this streamlines the process of analyzing and comparing the results. This reduces test session time, thus generating faster results.

The Nodes are remote devices that consist of a native OS, and remote Appium Servers. It receives requests from the Hub in the form of JSON test commands and executes them using Appium.
Appium Grid Architecture

Appium Grid Architecture

Learn to set up a Selenium Grid for Cross Browser Testing

Prerequisites of Appium Grid

Listed below are the prerequisites for setting up the Appium Grid and starting with the cross browser testing on multiple browser-device combinations (both Android and iOS) simultaneously:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

brew install wget
e
brew install carthage
brew install node
brew install maven
npm install -g appium
npm install -g ios-deploy

How to setup Appium Grid?

Step 1: Starting Hub by Launching Selenium Grid

The Hub is the central point in the Appium Grid, where Selenium Grid is used to route the JSON test commands to the nodes. It receives test requests from the client and routes it to the required Nodes.

Once the Selenium Grid is installed as mentioned in the prerequisites, set up the Hub (launching Selenium Grid) – open the command prompt, and navigate to the directory, where the Selenium Server Standalone jar file has been downloaded.

Start the Hub by passing the -role hub flag to the Selenium Standalone Server by entering the following command:

java -jar selenium-server-standalone-<version>.jar -role hub

This would start the hub automatically using port 4444 by default.

One can change the default port by adding an optional parameter -port when running the command.

One doesn’t have to specify the host name as it can be determined automatically. However, if the tester is using a VPN network, specifying the host becomes necessary.

To view the status of the hub, open a browser window and navigate to http://localhost:4444/grid/console

Step 2: Configure Appium Node JSON file and connect it to the Selenium Grid Hub

To set up Nodes for the Appium Grid, configure the JSON files for each of the node devices, such as done below for Device 1 (iOS 12, iPhone 8 Plus):

{
"capabilities":
[
{
"deviceName": "iPhone 8 Plus",
"browserName": "Safari",
"version":"12",
"maxInstances": 2,
"automationName": "XCUITest",
"platform":"iOS"
}
],
"configuration":
{
"cleanUpCycle":3000,
"timeout":30000,
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"url":"http://192.168.31.106:4628/wd/hub",
"host": "192.168.31.106",
"port": 4628,
"maxSession": 2,
"register": true,
"registerCycle": 5000,
"hubPort": 4444,
"hubHost": "192.168.31.106"
}
}

 

This JSON file will help connect the Hub and Nodes and act as a bridge in routing the relevant test to the required device at the Node.

Similarly, configure the JSON Files for other nodes (devices) to build the Appium Grid.

Then run the driver node by using the following command. Make sure that the port parameter mentioned here is the same as that on the Node Config JSON file.

appium -p 4728 --nodeconfig /absolute/path/nodeconfigdevice1.json

Note that the default port for Appium Client and server is 4723, while that of the Appium server and testing device is 4724. However, one can specify the port number to avoid confusion.

Step 3: Initialize the Mobile Drivers for Node Devices using Appium

Set the Desired Capabilities for Device 1 (iOS 12)using the following code This would be the first node for the Appium Grid:

DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("os_version", "12");
caps.setCapability("device", "iPhone 8 Plus");
caps.setCapability("real_mobile", "true");
caps.setCapability("browserstack.local", "false");



Setting up Desired Capabilities using BrowserStack Capabilities Generator

BrowserStack allows its users to set Desired Capabilities through Capabilities Generator as shown above.

Similarly, one can set the Desired Capabilities for other devices too (including Android devices) that would be used as Nodes in the Appium Grid.

The initialization of Node devices will help in allocating relevant tests to the targeted Node Device upon matching the Capabilities.

By performing the three steps above, testers can set up the Appium Grid, which would help them perform parallel testing on multiple devices by connecting the Appium Servers of the individual devices with a central Hub (Selenium Grid). The multiple device-browser combinations at the nodes will help in performing Cross Device Testing for the test scenarios.

Try Appium Testing for Free

The Way Ahead

Once the Appium Grid has been set up, testers will need access to real mobile devices to run their mobile tests. BrowserStack enables this by providing a real device cloud of thousands of mobile devices (both iOS and Android) for automated testing via Appium.

Additionally, there are in-built debugging tools to help the testers identify and resolve bugs without any hassles. BrowserStack thus facilitates Cross Platform Testing to verify an app’s compatibility with multiple devices and operating systems. It also facilitates parallel testing, thus accelerating test execution, test results and eventually, enabling significantly faster delivery of perfectly optimized apps.

Parallel Testing on BrowserStack

Tags
Appium

Featured Articles

Desired Capabilities in Appium

How to Download and Install Appium

Curated for all your Testing Needs

Actionable Insights, Tips, & Tutorials delivered in your Inbox
By subscribing , you agree to our Privacy Policy.
thank you illustration

Thank you for Subscribing!

Expect a curated list of guides shortly.