Selenium Grid is used to run multiple tests simultaneously on different browsers and platforms. Grid uses the hub-node concept. The hub is the central point wherein you load your tests. Nodes are the Appium instances that will execute the tests that you loaded on the hub.
Features of Mobile Grid
- Execute multiple instances of Appium tests in parallel which uses the same or different code base
- Reduces batch processing time. This is especially useful if you are testing on different platforms and SDK
- Code need not be on the system they execute. You can use any machine that contain the code and execute it. It will be send to the grid
- Multi platform and multi devices execute from your machines. You can shared the resources in your team instead of passing the devices around
Steps to setup
- Download Selenium Grid from here
- Make sure you have set up Appium. If not , refer to this page (OS X) or this (Windows)
Grid
- Input this in your terminal or command prompt
java -jar selenium-server-standalone.jar -role hub -port 4444 -host "My-Hub"
If you have difficulty finding your hostname , go to your terminal or command prompt
hostname
Your hostname will be displayed.
You will see a message something like this if Selenium Grid is launched successfully
10:17:28.995 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d35810:17:29.145 INFO [GridLauncherV3.lambda$buildLaunchers$5] - Launching Selenium Grid hub on port 44442020-04-20 10:17:29.657:INFO::main: Logging initialized @970ms to org.seleniumhq.jetty9.util.log.StdErrLog10:17:29.924 INFO [Hub.start] - Selenium Grid hub is up and running10:17:29.926 INFO [Hub.start] - Nodes should register to http://My-Hub:4444/grid/register/10:17:29.926 INFO [Hub.start] - Clients should connect to http://My-Hub:4444/wd/hub
Node
The next step we need is to setup the node. Nodes are the Appium instances that will execute the tests that you loaded on the hub. Connect your device (I am using an iOS device here) to your node machine. Let’s call this machine with hostname “My-Node”. If you do not know your node hostname , refer to the previous section.
Input this in terminal or command prompt , saying we are using port 4722
appium --port 4722 --nodeconfig config_ios.json
The JSON file (I call it “config_ios.json”) is in the section below
Executing the script
Usually if you are not using Selenium Grid, you may be getting your appium driver like the below (Java) :
driver = new AppiumDriver<>(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
Instead , we should be calling the Hub address (“My-Hub”
driver = new AppiumDriver<>(new URL("http://My-Hub:4444/wd/hub"), capabilities);
It will return the Appium driver and execute your test script on the node machine.
JSON File (node)
{
"capabilities":
[
{
"deviceName": "iPhone 10",
"platformVersion": "13.1.2",
"maxInstances": 1,
"platformName": "iOS",
"browserName": "Safari"
}
],
"configuration": {
"cleanUpCycle": 2000,
"timeout": 30000,
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"host": "My-Node",
"maxSession": 1,
"register": true,
"registerCycle": 5000,
"hubPort": 4444,
"hubHost": "192.168.1.1",
"hub": "http://192.168.1.1:4444",
"url":"http://192.168.1.2:4722/wd/hub",
"role": "node"
}
}
That’s it ! Let me know if you face any problem.
Created : 20 April 2020
Updated : 20 April 2020
Story extracted from : https://www.linkedin.com/pulse/setting-up-grid-appium-ivan-tay/