Simplifying Mobile App Testing with Appium 2.0 and Device Farms
Published: 2023-09-25 13:03:19

Setting up a mobile device farm for testing applications can be a daunting task, but recent advancements in tools like Appium 2.0 have made this process much more approachable and efficient. One such tool that stands out is the Appium Device Farm, known for its user-friendly interface and powerful capabilities. Let's walk through the steps to set up and streamline your mobile testing using this incredible tool.

***Prerequisite:***
Before we get started, ensure you have Appium version 2.0.X installed on your system. This is the backbone of our setup, allowing us to manage and interact with the devices effectively.

***Installing Appium Plugins***
Let's start by installing essential Appium plugins using the following commands:
> appium plugin install --source=npm appium-device-farm
> appium plugin install --source=npm appium-dashboard

***Tracking iOS Device Events***
For tracking iOS device events like device plugging and unplugging, we'll use the 'go-ios' module. Install it using npm:
> npm install -g go-ios

To ensure seamless integration, set the 'GO_IOS' environment variable. Open your .zshrc or equivalent file and add the following line:
> export GO_IOS="/usr/local/lib/node_modules/go-ios/dist/go-ios-darwin-amd64_darwin_amd64/ios"

***Completing the Installation***
With the plugins and necessary modules installed, we're almost ready to start using the setup.

***Starting the Appium Server***
Connect your physical devices to the server or utilize simulators. Start the Appium server using the following command:
> appium server -ka 800 --use-plugins=device-farm,appium-dashboard -pa /wd/hub --plugin-device-farm-platform=both

This command kickstarts the server and sets it up to use the plugins for managing the device farm effectively.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xypzd8p38l0fd5hf5ral.png)

***Accessing the Dashboard***
Voilà! You're now all set. Access the dashboard to monitor device availability at http://localhost:4723/device-farm/.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/55zrh9lyo0i1apsatfam.png)

***Running a Basic Demo Test***
Let's run a simple demo test to ensure everything is working smoothly. Below is a basic demo test using Appium to interact with an iOS application on an iPhone 14 simulator.
```
public class IOSBasicDemo {

    protected static IOSDriver driver = null;
    public WebDriverWait wait;

    @BeforeMethod
    public void setup() throws MalformedURLException {

        XCUITestOptions options = new XCUITestOptions();
        options.setDeviceName("iPhone 14");
        options.setPlatformVersion("16.4");

        String appPath = System.getProperty("os.name").equals("Windows 10") ? "\\apps\\TheApp.app" : "/apps/TheApp.app";
        options.setApp(System.getProperty("user.dir") + String.format(appPath, ""));

        driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), options);
        wait = new WebDriverWait(driver, Duration.ofSeconds(10));
    }

    @Test()
    public void TestScenario() throws InterruptedException {
        wait.until(ExpectedConditions.visibilityOfElementLocated(new AppiumBy.ByAccessibilityId("Photo Demo"))).click();
        Thread.sleep(3000);
    }

    @AfterMethod
    public void teardown() {
        driver.quit();
    }
}
```
***Exploring the Appium Device Farm Dashboard***
The Appium Device Farm dashboard offers a comprehensive view of your testing environment. From execution video capture to device logs and debug logs for troubleshooting, it provides crucial insights to enhance your testing experience.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p35j2jnu65temvk8zp7w.png)

A huge shoutout to the contributors at the [Appium Device Farm GitHub repository](https://github.com/AppiumTestDistribution/appium-device-farm) for their dedication and efforts, in making mobile testing more accessible and efficient!

Happy testing with Appium Device Farm! 🚀