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.
Sample test scripts are available in the python-appium-app-browserstack repository.
The sample test script in this section is compatible with W3C-based client bindings. Check out our JSON wire protocol-based scripts in the mjsonwp branch of the repository.
Run your first build
Run a sample Python test build using our following step-by-step tutorial.
Prerequisites
You need to have BrowserStack Username and Access key, which you can find in your account settings. If you have not created an account yet, you can sign up for a Free Trial
Ensure that Python v3 is installed on your machine.
Clone the sample repository
Run the following commands in your terminal/command-line to clone the sample Python repository and install the required dependencies.
Upload your app
Use one of the following options to upload an Android app (.apk
or .aab
file) or iOS app (.ipa
file) to BrowserStack servers.
-
Use Sample Apps
-
Upload via file manager
-
Upload via REST API
If you do not have an Android app or an iOS app at present, use one of our sample apps to run your first Appium test on BrowserStack App Automate. Choose from the options below
.apk
or .aab
file) or an iOS app (.ipa
file) :
Use our REST API to upload an Android app (.apk
or .aab
file) or an iOS app (
.ipa
file) from your local filesystem. Use the command-line tool cURL
to upload
your app as shown below :
The generated app_url
is a unique ID used to identify the uploaded app build. Take note of this app_url
as it will be used in steps ahead.
Configure test script
To run your first sample build, configure the following capabilities in the browserstack_sample.py
file of the cloned repository.
At the end of this step, you’ll have a sample test script, populated with capabilities, to replace in the browserstack_sample.py
file.
Set access credentials
Set the userName
and accessKey
capabilities to your BrowserStack Username and Access key respectively. These credentials are used to authenticate your tests.
Specify application under test
Use the app
capability to set the unique ID, the app_url
value obtained in Step 2, of your uploaded app. The uploaded app is installed on the device during test execution.
Set the device to run the test on
Use the deviceName
and platformVersion
capabilities to specify the device for testing.
Check out the capability builder page to view the supported device-OS combinations.
Copy and replace the test script file
Replace the contents in the browserstack_sample.py
file of the cloned repository with the following content.
Execute build on BrowserStack
You are now ready to run your build on BrowserStack.
In your terminal/command-line, navigate to the android
or ios
folder of the cloned sample Python repository and run the following command.
Facing issues? View common errors
Check the regular culprits
Check if the file is saved correctly and the packages & libraries required to run the test are installed. In most cases, searching on Google is helpful.
Authentication errors
If you are facing any authentication errors, check if the BrowserStack credentials are set correctly. You can find your Username and Access Key on the Account Settings page. Verify the credentials and try running the test again!
Facing issues while making code changes
Try to run the first test using our sample app and sample test case before running your own test. Update the browserstack.user
, browserstack.key
and app
capability in the test script to your credentials. In case of any issues, just reach out to our Support team.
Invalid app capability
Check if you’ve updated the app
capability value in the test script file with correct value of app_url
generated in Step 2 after you uploaded the app.
No tests run on executing the build using python command
Check if you’ve run the command from either the android
or ios
folder of the cloned Python repository.
Next steps
After you have successfully run your first test on BrowserStack, try integrating your test suite with BrowserStack.
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!