Cypress Tutorial
This documentation page is a quick tutorial on how to set up a small Cypress project and run its tests in parallel on TestingBot.
Install the Example
In this tutorial you create a small Cypress project with two spec files that test the TestingBot website, and run both specs in parallel on TestingBot. You don't need Cypress installed on your computer: the CLI uploads your project and TestingBot runs it.
Create the project directory:
mkdir cypress-testingbot-example
cd cypress-testingbot-example
mkdir -p cypress/e2e
Create cypress.config.js:
module.exports = {
e2e: {
baseUrl: 'https://testingbot.com',
supportFile: false
}
}
Create cypress/e2e/homepage.cy.js:
describe('TestingBot homepage', () => {
it('has the TestingBot title', () => {
cy.visit('/')
cy.title().should('include', 'TestingBot')
})
})
Create cypress/e2e/pricing.cy.js:
describe('TestingBot pricing', () => {
it('has the pricing title', () => {
cy.visit('/pricing')
cy.title().should('include', 'Pricing')
})
})
Configuration
Next, install the TestingBot Cypress CLI:
npm install -g testingbot-cypress-cli
The CLI reads its configuration and authentication details from a testingbot.json file. You can generate a new one in the project directory with:
testingbot-cypress init
The file contains these sections:
-
auth: your TestingBot
keyandsecret(from the member dashboard). TheTESTINGBOT_KEYandTESTINGBOT_SECRETenvironment variables override these values. - browsers: the browsers you want to run the tests on
- run_settings: options to customize the Cypress run
- tunnel_settings: options for the TestingBot Tunnel, which you only need to test an app that runs on your own computer or network
Replace its contents with this configuration:
{
"auth": {
"key": "TESTINGBOT_KEY",
"secret": "TESTINGBOT_SECRET"
},
"browsers": [
{
"browserName": "chrome",
"platform": "WIN11",
"version": "latest"
}
],
"run_settings": {
"cypress_project_dir": ".",
"build_name": "cypress-tutorial",
"cypressVersion": "14.2.0",
"npm_dependencies": {},
"package_config_options": {},
"start_tunnel": false,
"local_ports": [],
"realTimeLogs": true,
"parallel": 2
},
"tunnel_settings": {
"verbose": false
}
}
-
cypress_project_dir: the directory that containscypress.config.js."."works when you run the CLI from that directory. -
cypressVersion: the Cypress version that runs the tests. See Cypress versions for the supported versions. -
parallel: how many spec files run at the same time. With2, both specs run in parallel. -
start_tunnelandlocal_ports: only needed when the app under test runs on your computer. See Cypress testing for details.
Setup the Example
Your project directory should now contain these files:
cypress-testingbot-example/
├── cypress.config.js
├── testingbot.json
└── cypress/
└── e2e/
├── homepage.cy.js
└── pricing.cy.js
Run the tests
Run the tests from the project directory:
testingbot-cypress run
The test results, together with a video and logs of each test, are available in the TestingBot dashboard.
Expected output
A successful run prints output similar to this (shortened), and the CLI exits with code 0. If a test fails, the CLI exits with a non-zero code, so you can use it in CI.
✔ Cypress Project is now running on TestingBot
(Run Starting)
┌────────────────────────────────────────────────────────────────────────┐
│ Cypress: 14.2.0 │
│ Browser: Custom Chrome 156 │
│ Specs: 2 found (homepage.cy.js, pricing.cy.js) │
│ Searched: cypress/e2e/**/*.cy.{js,jsx,ts,tsx} │
└────────────────────────────────────────────────────────────────────────┘
Running: homepage.cy.js (1 of 2)
Cypress Job started.
View results on https://testingbot.com/members/builds/...
TestingBot homepage
√ has the TestingBot title (1217ms)
1 passing (1s)
...
(Run Finished)
Spec Tests Passing Failing
┌────────────────────────────────────────────────────────────────────────┐
│ √ homepage.cy.js 00:01 1 1 - │
├────────────────────────────────────────────────────────────────────────┤
│ √ pricing.cy.js 819ms 1 1 - │
└────────────────────────────────────────────────────────────────────────┘
√ All specs passed! 00:02 2 2 -
✔ Cypress Project has finished running on TestingBot