Remote Mobile Automation Execution and Mobile Device Farm Setup using Appium Device Farm
Setup Device Farm
There are bunch of methods for creating a free and open-source device farm, such as OpenSTF and Device Farmer. In this topic, I will explain how to set up using Appium Device Farm and Selenium Grid.
Appium Device Farm
This is the easiest one; you just need Appium 2 and the latest Node.js. Execute this command to install plugins for the device farm environment:
appium plugin install --source=npm appium-device-farm
After the installation is successful, you just need to run:
appium server -ka 800 --use-plugins=device-farm -pa /wd/hub --plugin-device-farm-platform=both
Voilà, your device farm using Appium Device Farm is ready. For more details and additional configuration, feel free to check out Appium Device Farm Github.
Selenium Grid Device Farm
This is the easiest second HAHAHA; you just need Appium 2 and Selenium Server Jar, download the latest jar of selenium grid from here Releases · SeleniumHQ/selenium (github.com) and execute this command, make sure Appium already run
java -jar selenium-server-<version>.jar standalone --config config.toml
config.toml file
[server]
port = 8888
[node]
detect-drivers = false
[relay]
url = "http://localhost:4723"
status-endpoint = "/status"
configs = [
"1", "{\"browserName\": \"chrome\", \"platformName\": \"android\"}",
"1", "{\"browserName\": \"safari\", \"platformName\": \"iOS\"}"
]
ps.
* port : This is where the Selenium Grid will be located, e.g., http://localhost:<port>
* detect-drivers = false : This setting will prevent the autodetection of available drivers on the current system and adding them to the Node
* url : This specifies the location of Appium
* status-endpoint : This defines the path for checking the status of Appium. By default, for Appium 2, it will be set to /status
* configs : These configurations are used for registering devices on the Selenium Grid
Done! We have already finished setting up the Selenium Grid device farm. By the way, you only need one device farm; you are free to choose any option you like.
Remote Mobile Automation Execution
This is another easy part, for real XD. This is an example of running Android and iOS automation remotely.
import org.openqa.selenium.MutableCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.ios.IOSDriver;
@Test
public void androidBrowserTest() throws MalformedURLException, InterruptedException {
URL gridUrl = new URL("http://<localhost>:<port>");
MutableCapabilities capabilities = new MutableCapabilities();
capabilities.setCapability("appium:automationName", "uiautomator2");
capabilities.setCapability("appium:device", "<your running devices, you can run command 'adb devices' to check the available devices>");
AndroidDriver driver = new AndroidDriver(gridUrl, capabilities);
//any logic
driver.quit();
}
@Test
public void iOSAppTest () throws MalformedURLException, InterruptedException {
URL gridUrl = new URL("http://<localhost>:<port>");
MutableCapabilities capabilities = new MutableCapabilities();
capabilities.setCapability("appium:automationName","XCUITest");
capabilities.setCapability("appium:deviceName", "<any simulator name available on your local>");
IOSDriver driver = new IOSDriver(gridUrl, capabilities);
//any logic
driver.quit();
}
Remember, navigating the seas of knowledge is more fun when you’re equipped with the compass of curiosity and the sail of imagination. Now, set your course for new horizons and let your ideas take flight on the winds of inspiration. THANKS FOR READING!