Hi, Testers, This article is about Appium Parallel Test Execution on real mobile devices.
Prerequisites:
I've used the below versions to execute the test flow.
In the appium parallel execution, the Appium server acts as a node. We can launch the Appium server using the .exe file.
We need to create a JSON file to create a node & these JSON files will help in interact with the real devices & with the hub. Please follow the simple steps to configure.
Prerequisites:
- Download & Install the latest Appium App.
- Eclipse.
- TestNG.
- Selenium Stand Alone Server jar.
- Real Devices.
I've used the below versions to execute the test flow.
- Appium App: v1.5.1,
- Selenium Stand Alone Server: 3.141.59,
- Eclipse: Eclipse IDE 2019‑12,
- TestNG: 7.0.0,
- Real Devices: Samsung version : 6.0 & Samsung version: 5.0.
Configure Selenium StandAlone Server:
We need to configure selenium standalone server as a .bat file. Kindly follow the below steps to configure:
- Create a folder.
- Create a new .txt file into the folder.
- In the .txt file add a command java -jar selenium-server-standalone-3.141.59.jar -role hub
- Save the text file as standaloneserver.bat (We can save a file with any desired variable name)
- Include the Selenium StandAlone Server jar file into the folder.
When a user clicks on the standaloneserver.bat, a command prompt will pop out & Selenium StandAlone Server will start to run, this acts as a hub.
Imp: Note the IP address of the hub we need it to use later to configure in our Java program.
In the appium parallel execution, the Appium server acts as a node. We can launch the Appium server using the .exe file.
We need to create a JSON file to create a node & these JSON files will help in interact with the real devices & with the hub. Please follow the simple steps to configure.
Device 1 node configuration:
{
"capabilities":
[
{
"deviceName": "Samsung",
"platformName": "Android",
"browserName":"Android",
"platformVersion": "6.0",
"maxInstances": 1
}
],
"configuration":
{
"cleanUpCycle":2000,
"timeout":30000,
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"url":"http://0.0.0.0:4723/wd/hub",
"host": "0.0.0.0",
"port": 4723,
"maxSession": 1,
"register": true,
"registerCycle": 5000,
"hubPort": "4444",
"hubHost": "10.120.30.18"
}
}
Capabilities:
{
"capabilities":
[
{
"deviceName": "Samsung",
"platformName": "Android",
"browserName":"Android",
"platformVersion": "6.0",
"maxInstances": 1
}
],
"configuration":
{
"cleanUpCycle":2000,
"timeout":30000,
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"url":"http://0.0.0.0:4723/wd/hub",
"host": "0.0.0.0",
"port": 4723,
"maxSession": 1,
"register": true,
"registerCycle": 5000,
"hubPort": "4444",
"hubHost": "10.120.30.18"
}
}
Capabilities:
- Capabilities are pretty straight forward, edit capabilities based on your device. One thing the user needs to note is the maxInstances. You need to configure maxInstances based on your requirements. maxInstances is how many instances the user needs to run the test. In my test, I need to run the test once so I've configured maxInstances as 1.
Configuration:
Under configuration, the user needs to concentrate on url, host, port, hubPort, hubHost.
- url: Appium server address (0.0.0.0) & server port (4723).
- host: Appium server address,
- port: 4723,
- hubPort: Port address from your selenium standalone server,
- hubHost: Host address from selenium standalone server
Device 2 node configuration:
{
"capabilities":
[
{
"deviceName": "Samsung",
"platformName": "Android",
"browserName":"Android",
"platformVersion": "5.0",
"maxInstances": 1
}
],
"configuration":
{
"cleanUpCycle":2000,
"timeout":30000,
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"url":"http://0.0.0.0:5000/wd/hub",
"host": "0.0.0.0",
"port": 5000,
"maxSession": 1,
"register": true,
"registerCycle": 5001,
"hubPort": "4444",
"hubHost": "10.120.30.18"
}
}
Edit capabilities based on your second mobile device. I've used Samsung Note so I've configured accordingly.
Imp: The user needs to change the url, host, port & registerCycle.
url:
Create two text files in a folder, copy-paste the Device 1 node configuration & Device 2 node configuration in the text files, save two txt files as .json.
Click the link to find the java code.
https://gist.github.com/Koguljava/8e3b5bacc4e171ae53d9f25092c8a3bb
Click the link to find the TestNG configuration:
https://gist.github.com/Koguljava/524f763d9320ef2c009b3e0bcf6ddcfe
Steps to Configure Appium app:
i. Open two appium desktop apps in parallel & insert two JSON files into the Node config file path.
Voila! It's all set to run, click on the Start Server button to start both the server & run the appium code from eclipse.
"capabilities":
[
{
"deviceName": "Samsung",
"platformName": "Android",
"browserName":"Android",
"platformVersion": "5.0",
"maxInstances": 1
}
],
"configuration":
{
"cleanUpCycle":2000,
"timeout":30000,
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"url":"http://0.0.0.0:5000/wd/hub",
"host": "0.0.0.0",
"port": 5000,
"maxSession": 1,
"register": true,
"registerCycle": 5001,
"hubPort": "4444",
"hubHost": "10.120.30.18"
}
}
Edit capabilities based on your second mobile device. I've used Samsung Note so I've configured accordingly.
Imp: The user needs to change the url, host, port & registerCycle.
url:
- Appium server address (0.0.0.0) & server port (5000). http://0.0.0.0:5000/wd/hub. The user no need to edit the host or server address, the only editable portion is the port or server port. Configure a unique port to interact with the second device.
Parallel execution will work only when the user configured to a unique port.
The next change is the host (Appium server address), port (server port). Change the register cycle to 5001.
Create two text files in a folder, copy-paste the Device 1 node configuration & Device 2 node configuration in the text files, save two txt files as .json.
Click the link to find the java code.
https://gist.github.com/Koguljava/8e3b5bacc4e171ae53d9f25092c8a3bb
Click the link to find the TestNG configuration:
https://gist.github.com/Koguljava/524f763d9320ef2c009b3e0bcf6ddcfe
Steps to Configure Appium app:
i. Open two appium desktop apps in parallel & insert two JSON files into the Node config file path.
Voila! It's all set to run, click on the Start Server button to start both the server & run the appium code from eclipse.