A step-by-step guide to help you integrate Bitbucket Pipelines with the BrowserStack device cloud for running all your Selenium tests on BrowserStack Automate.
You can run your automated tests on BrowserStack Automate using your existing Bitbucket pipelines setup. Bitbucket Pipelines uses bitbucket-pipelines.yml for configuration, and the same can be used to run your tests on BrowserStack too.
To run your tests, there are three things that we recommend you to do:
If you are already using environment variables to specify your BrowserStack authentication details, you can skip this step.
If not, we strongly recommend you not to hardcode the auth details in your code (and hence do not commit and check-in your auth keys into code repositories). This helps in both maintaining a secure codebase, as well as helping you flexibly run your tests using different service accounts based on your needs (for example, run pre-prod regression suites using a team account with higher parallels limit).
Go to your Bitbucket repository’s settings and add the following environment variables:
BROWSERSTACK_USERNAME: Your BrowserStack username
BROWSERSTACK_ACCESS_KEY: Your BrowserStack access key
You can then read these variables in your tests. Here is a sample code to demonstrate how that’s done:
Integrate test cases for privately hosted websites
If you are testing websites hosted locally as part of your testing or development environment, configure your bitbucket-pipelines.yml file to use the BrowserStack Local binary and route your tests through the local server.
If you chose to use BrowserStack Local binary as a way to establish a local connection, in the bitbucket-pipelines.yml file you must configure pipeline to automatically download and start the binary.
Edit your existing bitbucket-pipelines.yml file to include the code in the following snippets.
# For Linux-based systems, add the following commands in the given console to download the binary, run it, and stop its execution after the test has been executed.- wget "https://www.browserstack.com/browserstack-local/BrowserStackLocal-linux-x64.zip"
- unzip BrowserStackLocal-linux-x64.zip
- ./BrowserStackLocal --key $BROWSERSTACK_ACCESS_KEY --daemon start
- <your-test-command>- ./BrowserStackLocal --key $BROWSERSTACK_ACCESS_KEY --daemon stop
# For macOS-based systems, add the following commands in the given console to download the binary, run it, and stop its execution after the test has been executed.- wget "https://www.browserstack.com/browserstack-local/BrowserStackLocal-darwin-x64.zip"
- unzip BrowserStackLocal-darwin-x64.zip
- ./BrowserStackLocal --key $BROWSERSTACK_ACCESS_KEY --daemon start
- <your-test-command>- ./BrowserStackLocal --key $BROWSERSTACK_ACCESS_KEY --daemon stop
# For Windows-based systems, add the following commands in the given console to download the binary, run it, and stop its execution after the test has been executed.- wget "https://www.browserstack.com/browserstack-local/BrowserStackLocal-win32.zip"
- powershell.exe Expand-Archive BrowserStackLocal-win32.zip
- ./BrowserStackLocal-win32/BrowserStackLocal.exe --key %BROWSERSTACK_ACCESS_KEY% --daemon start
- <your-test-command>- ./BrowserStackLocal-win32/BrowserStackLocal.exe --key %BROWSERSTACK_ACCESS_KEY% --daemon stop
If you prefer to manage the Local connection through your test scripts, you can use the language bindings.
Apart from these configurations, you can set other Local options, such as, testing behind a proxy, folder testing, or using multiple local instances. Check out Introduction to Local Testing for more information.
Add the local capability to test scripts
Add the local capability to test scripts using the following code snippets. When you set this capability to true, BrowserStack resolves the request via the Local agent running in your network.