Appium grid configuration Example

As we all know, we use selenium grid to run our tests on different browsers/operating systems in parallel to reduce the execution time. Now we will increase our environment to run tests on mobile browsers (Android/iOS) using Appium.

A grid consists of a single hub, and one or more nodes (Desktop/Mobile), where hub receives all the test requests like browser, platform etc and redirects to node machines where tests will run. If you are new to grid concept, please understand Selenium Grid and configuring grid using json files.

If your list of devices/browsers/OS are more, then maintaining infrastructure to different combinations of mobile devices, browsers and Operating systems with different resolutions are very difficult.

You should look at cloud-based platforms for testing web and mobile applications with real physical devices and simulators devices, iPhones, iPads, Windows, & OSX. All these are supported by CrossBrowsersTesting. You can signup and try Free Trial - No Credit Card Required. For more detailed information on Execute tests on cloud using selenium

Let us see how to configure Appium servers (nodes) with Selenium Grid to run our tests on Desktop browsers, Android and IOS devices.

Before proceeding, please make sure Appium is installed successfully. If not please install Appium using Node.js. You can find detailed steps to install Appium using AppiumDesktop and using NodeJs.

Install Appium using below command

$ npm install -g appium

When we appended '-g' or '--global' to the command, it will install the current package context (ie, the current working directory) as a global package.

Steps to configure Appium with Selenium Grid for multiple devices/emulators.

Step 1: Launch Selenium Grid

Open a command prompt and navigate to the directory where you downloaded selenium-server-standalone jar file and type the following command:

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

Step 2: Configure Appium node JSON file for the device 1 (Android 6.0) and connect to Selenium Grid using below command

{
  "capabilities":
      [
        {
         "deviceName": "Galaxy",
          "browserName": "chrome",
          "version":"6.0",
          "maxInstances": 2,
          "platform":"Android"
        }
      ],
  "configuration":
  {
    "cleanUpCycle":3000,
    "timeout":30000,
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "url":"http://192.168.31.106:4625/wd/hub",
    "host": "192.168.31.106",
    "port": 4625,
    "maxSession": 2,
    "register": true,
    "registerCycle": 5000,
    "hubPort": 4444,
    "hubHost": "192.168.31.106"
  }
}

Command to run device1 node config json file. Make sure to sse the same port for parameter '-p' as specified on the nodeconfig json file.

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

Once the command is executed, you should see the node registered to the Selenium grid.

Step 3: Configure Appium node JSON file for the device 2 (Android 7.1.1) and connect to Selenium Grid

{
  "capabilities":
      [
        { 
		  "deviceName": "Nexus5",
		  "browserName": "chrome",
          "version":"7.1.1",
          "maxInstances": 2,
          "platform":"Android"
        }
      ],
  "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"
  }
}

Command to run device2 node config json file. Use the same port for parameter '-p' as specified on the nodeconfig json file.

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

Step 4: Configure Appium node JSON file for the device 3 (IOS) and connect to Selenium Grid

{
  "capabilities":
      [
        {
	  "deviceName": "iPhone 7",
	  "browserName": "Safari",
          "version":"10.3",
          "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"
  }
}

In the same way we can create multiple appium nodes for new devices based on the requirement, and connect them to the grid.

Here is the link to official Appium Node Configuration Example json file Config file.

NOTE: If we don't specify url, host, and port in the config file, the config will be auto updated to point to localhost:port which appium started on.

Step 5: After connecting nodes to the grid, you should see all the nodes registered in the grid console.

When we execute our tests, we pass capabilities into the RemoteWebDriver object, if all the capabilities are matched with the requested capabilities on the grid, then tests will be redirected to specific node.

The capabilities that are not specified will be ignored, but if you specify the capabilities that do not exist on your grid then and the test will fail to run.

Appium Tutorials: 

Add new comment