Mobile applications are becoming widely available on the market at the speed of light while development and testing of particular applications on multiple platforms and devices becomes a challenge. There can be multiple platforms (Android, iOS) and multiple devices which a Mobile App can support. However it involves a lot of resources and time for development to cover all of the tests across these devices.
Mobile Test Automation is a solution to save time and resources. In this use case we will cover the steps needed to configure Appium servers with Selenium Grid to run Mobile Test Automation. The steps explained in this use case will be similar when working with iOS devices. We will also cover how multiple mobile real/virtual devices connected/hosted on the same machine or distributed across different machines can be driven with the Appium framework and Selenium Grid. This use case will cover the steps to configure Appium with Selenium Grid for multiple mobile devices.
We will see how two android virtual devices (Samsung S4 and S5, or you can use any other brand of devices listed in Genymotion) are configured with the Appium server and Selenium Grid to be part of the test automation infrastructure.
Appium Client Library – The Client library used to script the test automation scripts to communicate with the Appium server.
Selenium Grid – Central Hub whose job would mostly be to redirect requests to the correct Appium server and in turn to the correct Device.
Appium Servers – Appium servers are nothing but the Node.js server hosted which can understand the Appium framework requests coming in the form of Webdriver REST APIs. These Appium Servers communicate with the respective Android devices configured with them in the form of JSON Wired Protocol.
Genymotion AVDs – The Genymotion is software which can host multiple android devices which is as good as attaching the real device to the particular machine. Note that default AVDs which come with Android SDK or any other AVDs providing software will also work for the scenario explained in the use case.
[See Also: Appium: iOS UI Software Test Automation]
You should see something as shown below:
List of devices attached
This is the command to show that we have 2 devices which are ready for use:
192.168.56.101:5555 is S4 Device and 192.168.56.102:5555 is S5 Device.
The objective of hosting Selenium Grid is to redirect the test script request to the correct device based on the desired capabilities set to decide which device to use for running the tests at run time. Use the following commands to host the Selenium Grid on port 4444.
java -jar selenium-server-standalone-###.jar -port 4444 -role hub
eg - java -jar selenium-server-standalone-2.47.1.jar -port 4444 -role hub
After executing this command the Selenium Grid is ready to listen for requests coming on port 4444 using the URL:
Now we have Selenium Grid hosted on an IP with a particular port where we can connect to. To configure 2 Running AVDs with Selenium Grid we need to create interfaces of the Appium Server. We have to run 2 instances of the Appium Server each associated with one of the Mobile devices and on another end connected to Selenium Grid.
Note: devicename is one of the keys of the Appium node which we are configuring. Here the JSON describes that the Appium node will be associated with the S4 device and the device will be listening for commands coming on the Appium node server address (URL key in JSON) on port 4723.
On the other side, hubPort and hubHost parameters decide which port and host machine Selenium Grid is hosted on and in turn registers the Appium node with it.
[See Also: Mobile Test Automation Using Robot Framework]
Open Command prompt and navigate to the location where Appium was installed. Run the following command to host the Appium node instance:
node.exe node_modules\appium\bin\appium.js --nodeconfig <path to appium_node_S4.json> -p 4723 –U 192.168.56.101:5555
Note: This command explains to the host Appium node server instance for devices which have UUID (192.168.56.101:5555) with the parameter –U and port 4723.
The Selenium grid http://<Selenium_Grid_Host_Machine_Ip>:4444/wd/hub will communicate with the Appium server instance on http://126.96.36.199:4723/wd/hub and in turn will reach out to the S4 device with the REST protocols.
Once this is up and running you will see the notification in the Selenium grid console as an Appium node is registered as shown below:
In the same way create the Appium node JSON configuration file for the S5 device as shown below and host another instance of the Appium node server –
Note: When hosting another instance of the Appium Node server for the S5 device we need to host it on a port other than the one that was used by the Appium server previously hosted for the S4 device i.e. 4723. So we choose 4724 as the port to host the Appium server for the S5 device and changed the device name to 192.168.56.102:5555 which the S5 device is running.
Check the Selenium Grid Console to see if both the nodes are registered correctly similar to the snapshot shown below:
Now both the Appium nodes are registered successfully to the Selenium Grid and ready to work with the Test Automation script.
Regardless of which programming language library we choose to write automation scripts, we need to set the desired capabilities for the Remote Webdriver. For e.g. let’s say we want to execute a script to launch a default email app on the S4 device. We will set the desired capabilities as shown below in the automation script.
desired_caps['platformName'] = 'ANDROID'
desired_caps['platformVersion'] = '4.4.2'
desired_caps['deviceName'] = '192.168.56.101:5555'
desired_caps['appPackage'] = 'com.android.email'
appactivity = '.activity.Welcome'
desired_caps['appActivity'] = appactivity
driver = webdriver.Remote('http://188.8.131.52:4444/wd/hub',
We have set deviceName = ‘192.168.56.101:5555’ which is the UUID of the S4 device in our scenario and our scripts are sending requests to the Selenium Grid instance hosted remotely on http://184.108.40.206:4444/wd/hub which is hosted on the same machine. If Selenium Grid is hosted on any other machine then the respective URL with the correct hostname/IP address should be passed to the Remote Webdriver. The requests coming to this instance will be redirected to the respective Appium node instance whose desired capability matches with the desired capability set in the script.
Similarly, if we need to launch an email app on the S5 device only one parameter needs to be changed in the script as shown below. Requests will be redirected to the S5 device by Selenium Grid to the respective Appium node server instance of the S5 device:
desired_caps['deviceName'] = '192.168.56.102:5555'
Access a special Introduction Package with everything you want to know about outsourcing your technology development. How should you evaluate a partner? What components of your solution that are suitable to be handed off to a partner? These answers and more below.