Parallel Testing in Appium on Real Devices

Save Time & Costs by Parallel Testing in Appium. Test on Real Android & iOS Devices Effortlessly

Get Started free
Home Guide How to perform Parallel Test Execution in Appium?

How to perform Parallel Test Execution in Appium?

By Hamid Akhtar, Community Contributor -

Mobile test automation is now almost exclusively associated with Appium. It is cross-platform, free, open-source, and can be used for native, hybrid, and web applications on Android and iOS. It can be installed on any operating system and works with many programming languages, such as Java, C#, Python, JavaScript, and many others.

As defined at Appium.io, Appium is based on the notion that testing native apps shouldn’t require integrating an SDK or recompiling your app. And also, you should be able to use the frameworks, tools, and testing methods you are already familiar with. Most importantly, you can test the app you submit to the marketplace. With its standard automation specification and API, it’s easy to say that Appium is useful for apps that run on multiple platforms, like Windows, Android, or iOS.

Due to the growing competitiveness, a quicker time to market (TTM) has become crucial for any organization to compete in the market today. Resorting to parallel test execution with Appium is the overall result.

How does Appium Work?

With a REST API exposed, Appium is fundamentally a webserver. In a nutshell, it accepts connections from a client, listens to the commands, executes them on a mobile device, and returns an HTTP response that represents the result. Client/server architectures open up many possibilities: you can write your test code in any language with an HTTP client API, but Appium client libraries are more convenient.

  • Another significant aspect of Appium that may be discussed in this context is that you are not required to develop and execute your tests in a particular language or framework. 
  • This requirement is satisfied by the WebDriver API, which encapsulates the vendor-provided frameworks. 
  • WebDriver (aka “Selenium WebDriver”), defines a client-server protocol (known as the JSON Wire Protocol).
  • With the client-server architecture, a client created in any language can send HTTP requests to the server. Every major programming language already has clients written in it.
  • As a result, you can use any test framework and test runner. The client libraries are just HTTP clients, so you can include them in your code however you like.

That is to say, Appium and WebDriver clients are “automation libraries” rather than “test frameworks.” Any technique you choose can be used to manage your test environment. As for automating web browsers, WebDriver has taken over as the de facto standard.

Importance of  Parallel Testing

The goal of adopting enterprise test automation should always be to run a test script on as many devices as possible. It lets you run tests, get results, and fix problems with the app you’re making quickly. 

  • When you switch from sequential to parallel testing in your QA routine, the importance of parallel testing becomes easily apparent. 
  • Moreover, manually starting mobile tests that run device by device doesn’t fit well with agile thinking. 
  • Appium is about automating tests to run simultaneously on an unlimited number of real mobile devices. 
  • Simulators and emulators are severely constrained in handling real hardware specifics and the number of concurrent instances that can be launched.
  • Therefore, it is usually advisable to test on actual devices. 
  • You must cleverly configure the device with the Appium server so that it can recognize the device, as this will allow you to catch errors that you might not otherwise be able to identify.

Aside from that, Appium’s desired capabilities take into account a wide range of variables, such as the automation engine, the whole platform description (OS, version, etc.), the application (name/link, run details, timeouts), and several other variables related to launching, execution, or device sessions.

Advantages of Parallel Testing with Appium

To utilize the advantages of Parallel Testing with Appium and expedite execution times, independent tests can be run in parallel. In particular, as part of a CI/CD pipeline and DevOps methodology, IT businesses embrace continuous testing to boost software quality and velocity. Continuous testing, however, demands efficient and simplified test automation. 

  • The importance of parallel testing is further seen when mixed with the new continuous testing methodology, which enables broad test coverage in the shortest execution time possible. 
  • In contrast, Appium parallel execution on multiple devices speeds up testing and considerably lowers the risk of constant quality visibility by assisting you in removing the bottleneck.
  • Previously, it only tested iOS and Android mobile apps. However, Appium now offers an additional step that checks Windows desktop applications.

Pro-Tip: It is best to use a Parallel Test Calculator to understand the number of parallel sessions required to achieve test coverage and build execution time goals.

BrowserStack App Automate Banner 7

Performing Parallel Test Execution in Appium using TestNG

Appium parallel execution on multiple devices is an integral part of BrowserStack that lets you run the same test or several tests simultaneously on different devices and OS versions. Your test suite’s runtime will be reduced, leading to faster builds and release times.

  • For this, a BrowserStack username and access key are required. Your access credentials can be found in your account settings after you sign up.
  • Make sure your machine has Maven and Java 8+ installed.
  • You can upload your iOS app (.ipa file) or Android app (.apk or .aab file) to BrowserStack servers using our REST API. 

From the GitHub repository, clone the TestNG integration sample code.

git clone https://github.com/browserstack/testng-appium-app-browserstack.git

Execute the subsequent commands to install the necessary dependencies:

# Test an android app
cd android/testng-examples
mvn clean

# Test an iOS app
cd ios/testng-examples
mvn clean

This will set up necessary dependencies, including the Java client library for Appium:

  <dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.0.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>com.browserstack</groupId>
<artifactId>browserstack-local-java</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>

Configure Appium’s desired capabilities:app capability & device capability.

In the TestNG sample integration code, parallel.conf.json file located in testng-examples/src/test/resources/com/browserstack/run_parallel_test directory has the Appium’s desired capabilities defined.

To provide the list of devices for parallel test execution, multiple devices are listed in the environment’s key.

{
"server": "hub-cloud.browserstack.com",
"username": "userid",
"access_key": "accesskey",

"capabilities": {
"project": "First TestNg Android Project",
"build": "TestNg Android Parallel",
"name": "parallel_test",
"browserstack.debug": true,
"app": "bs://<app-id>"
},
"environments": [
{
"device": "Google Pixel 3",
"os_version": "9.0"
},
{
"device": "Samsung Galaxy S10e",
"os_version": "9.0"
}
]
}
  • Using Capabilities Builder, you can investigate more Appium capabilities.
  • Once the needed features have been set up, you may initialize an Appium webdriver to do remote testing on BrowserStack. To achieve this, you must utilize a remote BrowserStack URL and your BrowserStack access credentials.

The remote Webdriver is initialized in the BrowserStackTestNGTest.java file found in the testng-examples/src/test/java/com/browserstack/run_parallel_test parallel test directory of the TestNG sample integration code, as shown below:

In the TestNG sample integration code, the remote Webdriver is initialized in the BrowserStackTestNGTest.java file found in the testng-examples/src/test/java/com/browserstack/run parallel test directory, as shown below:

//...

// Initialize the remote Webdriver using BrowserStack remote URL access credentials
// and desired capabilities defined above
driver = new AndroidDriver (
new URL("http://"+username+":"+accessKey+"@"+config.get("server")+"/wd/hub"), capabilities
);

//...

Talk to an Expert

The following step will assist you in setting up a test case with the TestNG framework that will run concurrently on various devices.

Access this directory in testng-examples/src/test/java/com/browserstack/run_parallel_test for BrowserStack’s sample apps.

Please adjust the test case if you are testing your own app.

package com.browserstack.run_parallel_test;

// imports...

public class ParallelTest extends BrowserStackTestNGTest {
@Test
public void test() throws Exception {
AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30)
.until(ExpectedConditions.elementToBeClickable(
MobileBy.AccessibilityId("Search Wikipedia")));
searchElement.click();

AndroidElement insertTextElement = (AndroidElement) new WebDriverWait(driver, 30)
.until(ExpectedConditions.elementToBeClickable(
MobileBy.id("org.wikipedia.alpha:id/search_src_text")));
insertTextElement.sendKeys("BrowserStack");

Thread.sleep(5000);

List<AndroidElement> allProductsName = driver.findElementsByClassName(
"android.widget.TextView");
Assert.assertTrue(allProductsName.size() > 0);
}
}

You may now run parallel tests on BrowserStack. Switch to the testng-examples/ directory in the TestNG sample integration code, then use the following command to run the test:

# Run using maven
mvn test -P parallel

On the App Automate dashboard or by using REST APIs, you can access the test execution results and debugging data such as video recording, network, and device logs.

Closing Notes

Deploying applications from conception to production without a hitch is feasible thanks to a cutting-edge methodology called DevOps for mobile app development. However, testing is far too often the bottleneck in DevOps. The entire cycle is held up by laborious testing. 

Parallel test execution in Appium solves this problem as it enables automated testing of native, hybrid, and mobile web apps and provides support for multiple programming languages. It truly empowers QA teams to test on multiple browsers, device,s and OS combinations without worrying about build times.

Try Parallel Testing

Tags
Automation Testing Parallel Testing

Featured Articles

How to run Appium Tests on macOS?

XPath in Appium: Tutorial

Automation Tests on Real Android & iOS Devices

Seamlessly Run Mobile App Automation Tests on real Android & iOS Devices