Integrate your test suite with BrowserStack
Integrate BrowserStack into your test suite using the BrowserStack SDK β a plug-and-play solution that takes care of all the integration steps for you!
SDK integration
Integrate your test suite with BrowserStack using the Pytest SDK.
Prerequisites
- You need to have BrowserStack Username and Access Key, which you can find in your account profile. If you have not created an account yet, you can sign up for a Free Trial.
- Pytestv4+, Python3 and Pip3 is installed on your machine.
Run a sample build
Run a sample Pytest test build on BrowserStack:
-
Get our sample project using one of the following options:
-
Option 1: Download the project browserstack/pytest-browserstack
-
Option 2: Clone the sample repository:
# Clone sample Python repository git clone -b main https://github.com/browserstack/pytest-browserstack cd pytest-browserstack
-
-
Set up the dependencies: Run the following commands on your terminal/command prompt to install the required dependencies.
MacOS/Linux:
# Create virtual environment python3 -m venv env source env/bin/activate # Install the required packages pip3 install -r requirements.txtWindows:
# Create virtual environment python3 -m venv env .\env\Scripts\Activate.ps1 # Install the required packages pip3 install -r requirements.txt -
Configure the
browserstack.ymlfile: Make sure to keep theturboScaleflag astrue.
The parallelsPerPlatform property determines the number of parallel threads to be executed. BrowserStackβs SDK runner will select the best strategy based on the configured value.
-
Example 1: If you have configured 3 platforms and set
parallelsPerPlatformto 2: a total of 6 (3 x 2) parallel threads will be used on BrowserStack. Your test suite would be split into 2 parts, each part running on all 3 configured platforms concurrently. -
Example 2: If you have configured 1 platform and set
parallelsPerPlatformto 15: a total of 15 (1 x 15) parallel threads will be used on BrowserStack. Your test suite would be split into 15 parts, each part running on the configured platform concurrently.
-
Run your build on BrowserStack: From the root directory of this project, run the following command:
browserstack-sdk pytest -s tests/bstack-sample-test.py -
View test results on the Automate TurboScale dashboard to see your test results.
Integrate your test suite
a. Install BrowserStack Python SDK
Execute the following commands to install BrowserStack Python SDK for plug-and-play integration of your test suite with BrowserStack.
python3 -m pip install https://sdk-assets.browserstack.com/python/browserstack_sdk-latest.tar.gz
browserstack-sdk setup --username YOUR_BROWSERSTACK_USERNAME --key YOUR_BROWSERSTACK_ACCESSKEY
b. Configure your browserstack.yml file
The auto-generated browserstack.yml file situated in the root location of your project holds all the required settings to run tests on BrowserStack. Make sure to keep the turboScale flag as true.
By default, BrowserStack Automate TurboScale provides prettified session logs and a video of the entire test. Additionally, you can enable the following features:
-
Test Reporting & Analytics: Enables Test Reporting & Analytics, an advanced test reporting and debugging tool that helps you analyze test failures much faster. If enabled, Test Reporting & Analytics collects test data using the SDK. This capability is enabled (set to
true) by default. -
Network logs: Enables network capture for the session in HAR format. Might reduce session performance slightly.
-
Console logs: Set the remote browserβs console log levels.
c. Test Localhost/Staging websites
BrowserStack Local Testing feature connects with test suites that test your localhost URL or staging websites. Enable browserstackLocal to true in the browserstack.yml file to turn on this feature.
If your staging environment is behind a proxy or firewall, additional arguments, such as proxy username, proxy password, etc., must be set. Check out Local Binary parameters to learn about additional arguments or Contact Support for assistance.
d. Use BrowserStackβs reporting features
You can leverage BrowserStackβs extensive reporting features using the following capabilities:
-
Build Name: Set a name to your build (usually the same as the build ID thatβs on your CI/CD platform).
- Accepted characters:
A-Z,a-z,0-9,.,:,-,[],/,@,&,',_. All other characters are ignored. - Character limit: 255
- Accepted characters:
-
Build Identifier: Select a dynamic build identifier that appends to the build name and generates a unique name on the BrowserStack dashboard.
- Project Name: Set a project name for your project.
e. Run your test suite on BrowserStack
Your test suite is now ready to run on BrowserStack! Prepend browserstack-sdk before your existing run commands to execute your tests on BrowserStack using the Pytest SDK.
Before:
pytest <path-to-test-files>
After:
browserstack-sdk pytest <path-to-test-files>
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!