Skip to main content
Introducing support for Selenium 4 and its BiDi APIs on BrowserStack Automate! Learn More!

Run your first Cypress test

Learn how to use the Kitchen Sink example app to run your first test on BrowserStack.

Overview

In this tutorial, we will use Cypress’ kitchen sink example app to run our tests. The Kitchen Sink app is an example app provided by Cypress to learn how Cypress works.

In this guide you will learn about:

Prerequisites

Run your first test

To run your first Cypress test with BrowserStack, perform the following steps:

Step 1: Install the BrowserStack CLI. The BrowserStack - Cypress CLI is a command-line tool that is used to enable communication between Cypress and BrowserStack. Use the npm command to install the BrowserStack - Cypress CLI as follows:

Command Line
# Install the BrowserStack Cypress CLI
npm install -g browserstack-cypress-cli

Step 2: Clone the Kitchen Sink app using the following command:

Command Line
# Clone the Kitchen Sink repo
git clone https://github.com/cypress-io/cypress-example-kitchensink.git

# Navigate to the cloned example directory
cd cypress-example-kitchensink

After you clone the repository, the folder structure of Cypress project is as follows:

app
...
cypress
|-- fixtures
|-- integration
|-- plugins
|-- support
cypress.json
...

Step 3: Install the dependent node modules. Use the npm command to install dependent node modules required to run the Kitchen Sink example app:

Command Line
npm install

Step 4: Create and configure the browserstack.json file. The browserstack.json file is a configuration file that contains specific configurations, such as BrowserStack credentials, capabilities, etc, required for running the tests. Use the init command to initialize the app project folder and create a boilerplate browserstack.json file using the following command:

Command Line
# Create a sample configuration file for configurations and capabilities
browserstack-cypress init

After the browserstack.json file is created, modify or add the mandatory configurations that are required to run the Cypress test as shown in the following sample code. The mandatory configurations are BrowserStack credentials, Cypress configuration file, browser-device combinations, and the number of parallels:

Note: Check out the supported devices and browsers to configure the testing combinations.
browserstack.json
{
  "auth": {
    "username": "YOUR_USERNAME",
    "access_key": "YOUR_ACCESS_KEY"
  },
  "browsers": [{
      "browser": "chrome",
      "os": "Windows 10",
      "versions": ["latest", "latest - 1"]
    },
    {
      "browser": "firefox",
      "os": "OS X Mojave",
      "versions": ["latest", "latest - 1"]
    },
    {
      "browser": "edge",
      "os": "OS X Catalina",
      "versions": ["latest"]
    }
  ],
  "run_settings": {
    "cypress_config_file": "./cypress.json",
    "cypress_version": "9",
    "project_name": "Cypress Kitchen Sink Example",
    "build_name": "Build no: 1",
    "parallels": 5,
    "exclude": ["some-folder/test.js", "static/*.pdf"],
}

Step 5: Set up the application server. The Kitchen sink sample app can be tested on BrowserStack using either the localhost website or using Cypress Kitchen Sink sample app public URL.

If you want to run the Cypress test using the Kitchen Sink web app hosted publicly at https://example.cypress.io/, you must replace all localhost URL instances with the public URL in the project folder.

Step 1: In your IDE, open the Kitchen Sink App project.

Step 2: Search the project for http://localhost:8080, and then replace all instances with https://example.cypress.io as shown in the following IDE sample:Cypress kitchen sink replace localhost

Ensure that you replace the instances in all *.spec.js files.

Step 3: Set the following Local configurations to the connection_settings object in your browserstack.json file:

browserstack.json
  ...
  "connection_settings": {
          "local": false,
      }
  ...

The tests in Kitchen Sink example use the http:\\localhost:8080 URL to access the application server. Use the following steps to start the application server.

Note: Check out the Cypress Kitchen Sink’s README for more information.

Step 1: Set up Local testing. Set the following Local configurations to the connection_settings object in your browserstack.json file:

browserstack.json
...
"connection_settings": {
        "local": true,
        "local_identifier": "My_Sample_Tutorial"
    }
...

Step 2: Start the webserver.

Command Line
npm start

Step 3: Verify the app is hosted.

Verify that the Kitchen Sink web app is hosted at http://localhost:8080.

Step 6: Run the test using the following command:

Command Line
browserstack-cypress run

View your test results

After you run your test, visit the Automate dashboard to view your test results as follows:

Automate Cypress Dashboard

All the tests run as part of each spec file are grouped by the browser combination. When you click any browser combination, you can see the detailed view that includes video logs, text logs, etc. If any tests run into an error, relevant screenshots are captured in the Screenshots tab.

On your command-line tool, you can see the completed tests along with their current status as the build execution progresses. After the tests are executed, you can access the results in the results folder that contains the HTML & JSON files with the build summary.

Next Steps

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