Run Tests in CI/CD

Learn how to run your Cypress tests in your CI/CD pipelines.

Running tests in CI/CD is very similar to the way you run the tests from your local machine.

Note: Check out our official CI/CD plugins here: Jenkins, Bamboo, TeamCity, Azure Pipelines, Circle CI, Bitbucket Pipeline, Travis CI, GitHub Actions, GitLab CI/CD.
  1. Clone your project / tests repository
  2. Install the BrowserStack-Cypress CLI
  3. Optionally, set up your application server if needed (for example, you want to set up a local server for every PR)
  4. Run your tests on BrowserStack. Optionally, set environment variables. See how to run tests in parallel.
  5. Optionally, receive updates about the test runs using polling or callback

Set environment variables

You can specify the auth and local-testing related settings via environment variables as well, instead of hard-coding them in browserstack.json. This makes it easier for you to test using the appropriate settings depending on whether you are running from your local machine or from your CI setup.

The CLI currently reads config from the following environment variables:

Env variable Accepted values
BROWSERSTACK_USERNAME Your BrowserStack username
BROWSERSTACK_ACCESS_KEY Your BrowserStack access key
BROWSERSTACK_LOCAL true if you want to use Local testing
BROWSERSTACK_LOCAL_IDENTIFIER The Local identifier you want to use
Note: If you are using our CI/CD plugins, these environment variables are automatically set depending on how you configured the plugin.

You don’t have to install Cypress or any of the npm packages on your CI machine. We will install them on our machines before running the test automatically.

Retrieve build details after running

Starting v1.6.0, when you run the tests in sync mode, the test results are saved to the results folder as HTML and JSON files. See generating reports to learn more.

Starting v1.4.0, the CLI generates a log/build_results.txt file that contains 2 lines with the details of the build ID, and the dashboard URL like below:

log/build_results.txt
BUILD_ID=<your_build_id>
BUILD_URL=<link_to_the_browserstack_dashboard_for_this_build>

Set up your application server

Set up an application server like you normally would (for example, you probably would host the app on localhost:3000).

But, additionally, you’ll have to set up a Local Testing connection. Make sure the local testing connection is established before running the tests, and is alive at least until all the tests are done running. In most cases, this means that you will have to do one of the following:

  • Run the tests in sync mode (using the --sync arg)
  • You have to poll for status change before terminating the Local testing connection, or
  • Handle a callback, and terminate Local testing connection

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

Is this page helping you?

Yes
No

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!

Talk to an Expert
Talk to an Expert