Skip to main content
Transform your testing process with: Real Device Features, Company-wide Licences, & Test Observability

Run Tests in CI/CD

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

Running tests in CI/CD is similar to how you run the tests from your local machine. It involves the following steps:

  1. Clone your project or test repository
  2. Install the BrowserStack-Cypress CLI
  3. Optionally, set up your application server if required. For example, if you want to set up a local server for every pull request.
  4. Run your tests on BrowserStack. Optionally, set environment variables. Check out 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 authentication and local-testing related settings via environment variables as well, instead of writing them in the browserstack.json file. 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 configuration from the following environment variables:

Environment variable Accepted values
BROWSERSTACK_USERNAME Your BrowserStack User Name
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’ve configured the plugin.

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

Retrieve build details after running

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

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

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 as required. For example, you may want to host the app on localhost:3000.

However, you will need to set up a Local Testing connection. Make sure the Local Testing connection is established before running the tests, and the connection is alive at least until all the tests have completed running. In most cases, this means that you will have to do one of the following:

  • Run the tests in sync mode by using the --sync argument,
  • Poll for status change before terminating the Local Testing connection, or
  • Handle a callback, and terminate the 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
Download Copy