Parallel Testing with App Automate
Parallel Testing is a BrowserStack feature that allows you to run same test or different tests simultaneously across different device and OS version combinations. It will help you to reduce the run time of your test suite, resulting in faster build times and releases.
For example, execution time of a test suite which takes 30 minutes running sequentially can be brought down to as low as 3 minutes by running 10 parallel tests (with the assumption that all your test cases take approximately the same time).
In this guide, you will learn how to :
- Setup your environment
- Upload your app
- Configure and run parallel tests
- View test execution results
1. Setup your environment
- You will need a BrowserStack
username
andaccess_key
. If you haven’t created an account yet, sign up for a free trial or purchase a paid plan. After signup, you can obtain your access credentials from account settings - Ensure you have Java 8+ installed on your system. You can download updated Java versions from java.com
- Ensure you have the
Maven
installed on your system. To installMaven
, follow steps outlined in the installation guide - You will need access to your Android app (
.apk
or.aab
file) or iOS app (.ipa
file)
.apk
or .ipa
file and are looking to simply try App Automate, you can download and test using our sample Android app or sample iOS app.
2. Upload your app
Upload your Android app (.apk
or .aab
file) or iOS app (.ipa
file) to BrowserStack servers using our REST API. Here is an example cURL
request to upload app on App Automate :
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
-F "file=@/path/to/apk/file"
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" ^
-X POST "https://api-cloud.browserstack.com/app-automate/upload" ^
-F "file=@/path/to/apk/file"
Ensure that @
symbol is prepended to the file path in the above request. A sample response for the above request is shown below:
{
"app_url" : "bs://j3c874f21852ba57957a3fdc33f47514288c4ba4"
}
Please note the app_url
value returned in the API response (bs://j3c874.....
in the above example). We will use this value to set the application under test while configuring the test later on.
- App upload will take a few seconds to about a minute depending on the size of your app. Do not interrupt the
cURL
command until you get the response back. - If you upload an iOS app, we will re-sign the app with our own provisioning profile to be able to install your app on our devices during test execution.
3. Configure and run parallel tests
Setup your project
Clone the JUnit sample integration code from our GitHub repository.
git clone https://github.com/browserstack/junit-appium-app-browserstack.git
Next, execute the following commands to install required dependencies:
# Test an android app
cd android/junit4-examples
mvn clean
# Test an iOS app
cd ios/junit4-examples
mvn clean
junit5-examples
directory in the JUnit sample integration code repository and follow the steps outlined here.
This will install requisite dependencies including Appium’s Java client library :
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</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>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.0.0</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
Desired capabilities are a series of key-value pairs that allow you to configure your Appium tests on BrowserStack. The following capabilities are required :
-
app
capability : Its used to specify your uploaded app that will be installed on device during test execution. Use theapp_url
obtained in Upload your App section to set its value. -
device
capability : Its used to specify the BrowserStack device you want to run the test on.
In the JUnit sample integration code, Appium’s desired capabilities are defined in the parallel.conf.json
file located in the junit4-examples/src/test/resources/com/browserstack/run_parallel_test
directory. Note the multiple devices listed in environments
key to specify the list of devices for parallel test execution.
{
"server": "hub-cloud.browserstack.com",
"username": "YOUR_USERNAME",
"access_key": "YOUR_ACCESS_KEY",
"capabilities": {
"project": "First Junit4 Android Project",
"build": "Junit4 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"
}]
}
{
"server": "hub-cloud.browserstack.com",
"username": "YOUR_USERNAME",
"access_key": "YOUR_ACCESS_KEY",
"capabilities": {
"project": "First Junit4 iOS Project",
"build": "Junit4 iOS Parallel",
"name": "parallel_test",
"browserstack.debug": true,
"app": "bs://<app-id>"
},
"environments": [{
"device": "iPhone 11 Pro",
"os_version": "13"
}, {
"device": "iPhone 11 Pro Max",
"os_version": "13"
}]
}
- You can explore other Appium capabilities using our Capabilities Builder
Create remote Webdriver
Once you have configured desired capabilities, you can initialize an Appium webdriver to test remotely on BrowserStack. In order to do so, you need to use a remote BrowserStack URL along with your BrowserStack access credentials.
In the JUnit sample integration code, the remote Webdriver is initialised in the BrowserStackJUnitTest.java
file located in the junit4-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("https://"+username+":"+accessKey+"@"+config.get("server")+"/wd/hub"), capabilities
);
//...
//...
// Initialize the remote Webdriver using BrowserStack remote URL access credentials
// and desired capabilities defined above
driver = new IOSDriver<IOSElement> (
new URL("https://"+username+":"+accessKey+"@"+config.get("server")+"/wd/hub"), capabilities
);
//...
- Setting
BROWSERSTACK_USERNAME
&BROWSERSTACK_ACCESS_KEY
environment variables or by - Setting
username
&access_key
parameters inparallel.config.json
file located injunit4-examples/src/test/resources/com/browserstack/run_parallel_test
directory
Setup your test-case
This step will help you setup a test case with JUnit framework that will execute in parallel on multiple devices. In the JUnit sample integration code, we have provided a sample test-case in junit4-examples/src/test/java/com/browserstack/run_parallel_test
directory for BrowserStack’s sample apps. If you are testing your own app, please modify the test case accordingly.
If you are using your own app, modify the following code as per your test case:
package com.browserstack.run_parallel_test;
// imports...
public class ParallelTest extends BrowserStackJUnitTest {
@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");
assertTrue(allProductsName.size() > 0);
}
}
If you are using your own app, modify the following code as per your test case:
package com.browserstack.run_parallel_test;
// imports...
public class ParallelTest extends BrowserStackJUnitTest {
@Test
public void test() throws Exception {
IOSElement textButton = (IOSElement) new WebDriverWait(driver, 30)
.until(ExpectedConditions.elementToBeClickable(
MobileBy.AccessibilityId("Text Button")));
textButton.click();
IOSElement textInput = (IOSElement) new WebDriverWait(driver, 30)
.until(ExpectedConditions.elementToBeClickable(
MobileBy.AccessibilityId("Text Input")));
textInput.sendKeys("hello@browserstack.com" + "\n");
Thread.sleep(5000);
IOSElement textOutput = (IOSElement) new WebDriverWait(driver, 30)
.until(ExpectedConditions.elementToBeClickable(
MobileBy.AccessibilityId("Text Output")));
assertEquals(textOutput.getText(),"hello@browserstack.com");
}
}
Run the test
You are ready to run parallel tests on BrowserStack. In the JUnit sample integration code, switch to junit4-examples/
directory, and run the test using command :
# Run using maven
mvn test -P parallel
4. View test execution results
You can access the test execution results, and debugging information such as video recording, network and device logs on App Automate dashboard or using our REST APIs.
Need some help?
If you have any queries, please get in touch with us.
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!