Parallel Testing is a feature of BrowserStack that allows you to run the same test or different tests simultaneously on different combinations of device and operating system versions. It will help you reduce the execution time of your test suite, resulting in faster build times and releases.
For example, the execution time of a test suite that takes30 minutesrunning sequentially can be reduced to as low as3 minutesrunning 10 parallel tests (assuming all your test cases take roughly the same time).
Use:Your App Automate plan must have enough licenses to be able to run parallel tests. If more tests are activated than you have subscribed to, they will be queued or discarded.
In this guide, you will learn how to:
- set up your environment
- Upload your application
- Configure and run parallel tests
- View test execution results
Use:If you have already passed through ourRun your first testguide, you can jump to theConfigure and run parallel testssection.
1. Set up your environment
- You will need a BrowserStack
Username
yaccess key
. If you haven't created an account yet, sign up for oneFree Trialor buy apaid plan. After registering, you can get your login credentials fromaccount settings - Make sure you have Python 3.6+ or Python 2.7+ installed on your system. You can download updated versions of Python fromPython.org
- Make sure you have package manager
nugget
installed on your system. Installnugget
, follow the steps described in theinstallation guide - You will need access to your Android app (
.apk
o.aab
file) or iOS app (.ipa
archive)
Use:If you don't have a.apk
o.ipa
and are looking to just try App Automate, you can download and try using ourandroid application exampleoexample application for iOS.
2. Upload your application
Upload your Android app (.apk
o.aab
file) or iOS app (.ipa
file) to BrowserStack servers using our REST API. here is an examplerice
Request to upload the app to App Automate:
- OS X y Linux
- windows
rice-tu "YOUR_USERNAME:YOUR_ACCESS_KEY" \-XCORREO"https://api-cloud.browserstack.com/app-automate/upload" \-F "file=@/path/to/apk/file"
rice-tu "YOUR_USERNAME:YOUR_ACCESS_KEY"^-XCORREO"https://api-cloud.browserstack.com/app-automate/upload"^-F "file=@/path/to/apk/file"
make sure that@
The symbol is prepended to the file path in the above request. Below is a sample response for the above request:
{ "application_url" : "bs://j3c874f21852ba57957a3fdc33f47514288c4ba4"}
Keep in mind theapp_url
return value in API response (bs://j3c874.....
in the example above). We'll use this value to set the app under test as we set up the test later.
Use:
rice
command until you get the response.
3. Set up and run parallel tests
configure your project
Clone theBehave sample integration codefrom our GitHub repository.
git clone https://github.com/browserstack/behave-appium-app-browserstack.git
Then, run the following command from the project's base directory to install the required dependencies:
# Test an Android applicationnuggetinstall -randroid/requisitos.txt# Test an iOS appnuggetinstall -rios/requirements.txt
This will install the necessary dependencies, includingA Python client library for Appium:
behave==1.2.6selenium==3.141.0Appium-Python-Client==0.52;python_version < '3.0'Appium-Python-Client==1.0.2;python_version >= '3.0'browserstack-local==1.2.2paver = =1.3.4psutil==5.7.2
Configuring Appium Desired Capabilities
The desired capabilities are a series of key-value pairs that allow you to set up your Appium tests on BrowserStack. The following capabilities are required:
browserstack.usuario
capacity: used to specify your BrowserstackUsername
credentialbrowserstack.clave
capacity: used to specify your Browserstackaccess key
credentialapplication
capacity: used to specify the loaded application to be installed on the device during the test execution. Use theapp_url
obtained inUpload your applicationsection to set its value.device
capacity – Used to specify the BrowserStack device on which you want to run the test.
In itBehave sample integration code, the desired capabilities of Appium are defined in theconfig.json
file located in theexamples/run-parallel-tests
directory. Note the use ofenvironments
key to specify a list of devices for parallel test execution.
- Android
- iOS
{ "capabilities": { "browserstack.usuario" : "YOUR USERNAME", "browserstack.clave" : "YOUR_ACCESS_KEY", "project": "Android First Behave Project", "build": "Behave Android in parallel", "name": "parallel_test", "navegadorstack.debug": TRUE, "application": "bs://" }, "environments": [{ "device": "Google Pixel 3", "operating system version": "9.0" }, { "device": "Samsung Galaxy S10e", "operating system version": "9.0" }]}
{ "capabilities": { "browserstack.usuario" : "YOUR USERNAME", "browserstack.clave" : "YOUR_ACCESS_KEY", "project": "Proyecto First Behave iOS", "build": "Behave iOS in Parallel", "name": "parallel_test", "navegadorstack.debug": TRUE, "application": "bs://" }, "environments": [{ "device": "iPhone 11 Pro", "operating system version": "13" }, { "device": "iPhone 11 Pro Max", "operating system version": "13" }]}
Use:
NAVEGADORSTACK_USERNAME
&NAVEGADORSTACK_ACCESS_KEY
Environment Variables
Create a remote web controller
Once you've configured the desired capabilities, you can initialize an Appium web driver to test remotely on BrowserStack. To do this, you must use a remote BrowserStack URL along with the desired capabilities.
In itBehave sample integration code, the remote Webdriver is initialized on theenvironment.py
file located in theexamples/run-parallel-tests/features
directory as shown below:
#...# Initialize the remote Webdriver using the BrowserStack remote URL # and the desired capabilities defined above context.browser = web controller.Remote ( desired_capabilities=desired_capabilities, command_executor="http://hub.browserstack.com/wd/hub" )#...
Set up your test case
This step will help you set up a test case with the Behave Framework that will run in parallel on multiple devices. In itBehave sample integration code, we have provided an example test case inexamples/run-parallel-tests/features
directory for BrowserStack sample applications. If you are testing your own application, modify the test case accordingly.
- Android
- iOS
Define the scenario you want to test in the application inparallel_test.feature
archive:
Feature: Wikipedia search functionality scenario: I can find search results Since I open the application and search for the keyword "BrowserStack", then the search results should appear
Provide the implementation of the steps used in the scenario inpasos.py
archive:
matter timeof appium.webdriver.common.mobileby matter MobileByof selenium.webdriver.support.ui matter WebDriverWaitof selenium.webdriver.support matter expected_conditions as CE@given(tu'I open the application and search for the keyword "{keyword}"')definitely paso_impl(context, keyword): search_item = WebDriverWait(context.browser, 10).until( CE.presence_of_located_element((MobileBy.ACCESSIBILITY_ID, "Search Wikipedia")) ) search_item.click() search_input = WebDriverWait(context.browser, 30).until( CE.element_to_be_clickable((MobileBy.ID, "org.wikipedia.alpha:id/search_src_text")) ) search_input.send_keys(keyword) time.sleep(5)@so(tu'Search results should appear')definitely paso_impl(context): elements = context.browser.find_elements_by_class_name("android.widget.TextView") claim Len(elements) > 0, "unpopulated results"
Define the scenario you want to test in the application inparallel_test.feature
archive:
Feature – Text check in sample app scenario – displayed text must match input text.
Provide the implementation of the steps used in the scenario inpasos.py
archive:
matter timeof appium.webdriver.common.mobileby matter MobileByof selenium.webdriver.support.ui matter WebDriverWaitof selenium.webdriver.support matter expected_conditions as CE@given('I open the app and click the Text button')definitely paso_impl(context): element = WebDriverWait(context.browser, 30).until( CE.presence_of_located_element((MobileBy.ACCESSIBILITY_ID, "Text Button")) ) element.click()@so(tu'Type "{text}" and press enter')definitely paso_impl(context, text): text input = WebDriverWait(context.browser, 30).until( CE.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID, "Text Input")) ) text input.send_keys(text+"\norte") time.sleep(5)@so(tu'Verify that the displayed text matches the input text')definitely paso_impl(context): text_output = WebDriverWait(context.browser, 30).until( CE.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID, "text output")) ) and text_output!=None y text_output.text=="hola@browserstack.com": claim TRUE the rest: claim FALSE
run the test
You are ready to run parallel tests on BrowserStack. In itBehave sample integration code, switch toexamples/run-parallel-tests
directory, and run the test using the command:
# Run using paverpaver run parallel_tests
4. View the results of the test run
You can access test run results and debugging information such as video recording, network, and device logs.App Automation Dashboardor using ourAPI REST.
I need help?
If you have any questions, pleaseContact us.
Was this page helpful?
We're sorry to hear that. Please share your feedback so we can do better.
Get in touch with ourSupport teamfor immediate help as we work to improve our documents.
We are continually improving our documents. We'd love to know what you liked
Thank you for your valuable comments.