Run your first Cypress test
Learn how to use the Kitchen Sink example app to run your first test on BrowserStack.
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
- Ensure that you understand Cypress fundamentals and how Cypress runs tests.
- 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 or purchase a plan.
- NodeJS version 12 or higher is installed.
To run your Typescript test with Cypress, check out our Typescript repository.
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:
# Install the BrowserStack Cypress CLI
npm install -g browserstack-cypress-cli
Step 2: Clone the Kitchen Sink app using the following command:
# Clone the Kitchen Sink repo for Cypress v10 and higher
git clone https://github.com/cypress-io/cypress-example-kitchensink.git && cd cypress-example-kitchensink
# Clone the Kitchen Sink repo for Cypress v9 and lower
git clone https://github.com/cypress-io/cypress-example-kitchensink.git && cd cypress-example-kitchensink && git checkout ab10094ef7b199ae7febafec413a0626414bcd3c
After you clone the repository, the Cypress project will be in the following structure:
app
...
cypress
|-- fixtures
|-- e2e
|-- support
cypress.config.js
...
app
...
cypress
|-- fixtures
|-- integration
|-- plugins
|-- support
cypress.json
...
Step 3: Use the npm
command to install dependent node modules required to run the Kitchen Sink example app:
npm install
Step 4: Create and configure the browserstack.json
file which contains configurations, such as BrowserStack credentials, capabilities, etc., that are required for running the tests. Use the following init
command to initialize the app project folder and create a boilerplate browserstack.json
file:
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:
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.config.js",
// For Cypress v9 or lower using the following configuration
// "cypress_config_file": "./cypress.json",
"cypress_version": "13.latest",
"npm_dependencies": {
"add-your-npm-package-1-for-test-run-here": "npm-package-version",
"add-your-npm-package-2-for-test-run-here": "npm-package-version"
},
"project_name": "Cypress Kitchen Sink Example",
"build_name": "Build no: 1",
"parallels": 5,
"exclude": ["some-folder/test.js", "static/*.pdf"]
}
}
If you are using any external npm packages in your Cypress tests, add those under npm_dependencies
in the browserstack.json file.
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 6: In your IDE, open the Kitchen Sink App
project.
Step 7: Search the project for http://localhost:8080
, and then replace all instances with https://example.cypress.io
as shown in the following IDE sample:
Ensure that you replace the instances in all *.spec.js
files.
Step 8: 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.
Check out the Cypress Kitchen Sink’s README for more information.
Step 6: 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 7: Start the webserver.
npm start
Step 8: Verify the app is hosted.
Verify that the Kitchen Sink web app is hosted at http://localhost:8080
.
Step 9: Run the test using the following command:
browserstack-cypress run
View your test results
After you run your test, visit the Automate dashboard to view your test results as follows:
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.
Debug builds and analyze trends with Test Observability
Level up your Cypress testing on BrowserStack with Test Observability - with advanced test reporting, debugging, smart failure analysis, and rich insights for your test suites.
Test Observabilty works automatically for all users running Cypress v10 and above. You can explicitly turn off Test Observability by turning the testObservability
flag to false
. You can explore additional configurations and learn how to use Test Observability for Cypress here.
Please note that Test Observability currently cannot be used alongside existing test reporters like mochawesome, and will automatically disable any other reporters you have set up.
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
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!