Run Appium tests using Python | BrowserStack Docs
Appium with Python
Test your native and hybrid apps on a real device cloud. This guide helps you run your first test build on a real Android or iOS device on BrowserStack.
In this document, you’ll learn how to set up your Python Appium testing environment, configure your test settings, and execute your first automated test on BrowserStack’s real device cloud. We’ll walk you through each step, from initial setup to viewing your test results on the dashboard.
Onboard faster with Test Companion
Launch in your IDE. Chat with the AI assistant to configure and run your first build instantly.
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.
Run a sample build
Run a sample Python test build using BrowserStack SDK with the following steps:
Clone sample repository
Clone our sample Git repository using the following commands:
git clone https://github.com/browserstack/python-appium-app-browserstack
cd python-appium-app-browserstack
Set up the dependencies
Install the required dependencies by running the following command in your terminal/command-line:
python3 -m venv env
source env/bin/activate
pip3 install -r requirements.txt
python3 -m venv env
.\env\Scripts\Activate.ps1
pip3 install -r requirements.txt
Configure your browserstack.yml config file
The browserstack.yml file holds all the required capabilities to run your tests on BrowserStack. It is found in your project’s (android/ios) root folder and is part of downloaded sample.
Set access credentials
Set userName and accessKey properties in the browserstack.yml file to authenticate your tests on BrowserStack.
Select Android or iOS devices from a list of 150+ available combinations:
Use one of our sample apps to run your first Appium test on BrowserStack App Automate. Choose from the options below:
Platform
Select an OS to choose the devices from below
Android
iOS
Update the browserstack.yml config file
Copy and replace the following config in the browserstack.yml file available in the root directory of this project.
userName: YOUR_USERNAME
accessKey: YOUR_ACCESS_KEY
framework: python
app: YOUR_APP_ID
platforms:
- YOUR_FIRST_OS_TYPE: YOUR_FIRST_OS
YOUR_FIRST_BROWSER_TYPE: YOUR_FIRST_BROWSER
YOUR_FIRST_BROWSER_VERSION_TYPE: 'YOUR_FIRST_BROWSER_VERSION'
- YOUR_SECOND_OS_TYPE: YOUR_SECOND_OS
YOUR_SECOND_BROWSER_TYPE: YOUR_SECOND_BROWSER
YOUR_SECOND_BROWSER_VERSION_TYPE: 'YOUR_SECOND_BROWSER_VERSION'
- YOUR_THIRD_OS_TYPE: YOUR_THIRD_OS
YOUR_THIRD_BROWSER_TYPE: YOUR_THIRD_BROWSER
YOUR_THIRD_BROWSER_VERSION_TYPE: 'YOUR_THIRD_BROWSER_VERSION'
browserstackLocal: true
buildName: browserstack-build-1
projectName: BrowserStack Sample
Run a sample build
Based on the devices and app selected, cd to the right project, install dependencies, and run a sample test build on BrowserStack
cd android
browserstack-sdk python browserstack_sample.py
cd ios
browserstack-sdk python browserstack_sample.py
If a test run stops due to a crash, you can stop the build from running by clicking the Stop build option from the App Automate dashboard.
- After you run your test, visit the App Automate dashboard to view your test results.
- If you want to toggle between BrowserStack and your Local device grid when using BrowserStack SDK, refer to the commands here.
Next steps
After you have successfully run your first test on BrowserStack, try integrating your test suite with BrowserStack.