Configure Cypress Cloud the way your team works (Test Automation)
Learn Configure Cypress Cloud the way your team works (Test Automation) step by step with clear examples and exercises.
Why This Matters
Welcome to this full guide on setting up Cypress Cloud for your team's test automation using JavaScript. By the end of this tutorial, you will have a solid understanding of how to use Cypress Cloud to improve your team's testing workflow and ensure high-quality software releases.
Why This Matters
In today's fast-paced development environment, it is essential to have efficient test automation tools that help catch bugs early and maintain the quality of your applications. Cypress Cloud offers a powerful solution for managing tests and providing insights into their reliability over time. By orchestrating runs and offering features like smart parallelization, flake management, and analytics, Cypress Cloud ensures feedback remains fast as your test suite grows.
Prerequisites
To follow along with this tutorial, you'll need:
- Node.js (v14.x or later) installed on your system
- A basic understanding of JavaScript and the Cypress testing framework
- Familiarity with Git and GitHub for version control
Core Concept
Cypress Cloud is a companion service to the open-source Cypress app, designed to help teams manage the quality of their tests and applications more effectively. It provides valuable insights into your test suite's reliability over time and orchestrates runs to ensure feedback remains fast as your suite grows.
Setting Up Cypress Cloud
To get started with Cypress Cloud:
- Sign up for a free trial at Cypress Cloud (skip this step if you already have an account).
- Install the Cypress Cloud CLI by running
npm install -g cypress-cli. - Initialize your project with Cypress using
cypress initand navigate to the newly createdcypressfolder. - Configure your test runner by adding the following lines to the
cypress.jsonfile:
{
"baseUrl": "http://your-app-url",
"viewportWidth": 1280,
"viewportHeight": 720,
"chromeWebSecurity": false,
"env": {
"cypress_base_url": "http://your-app-url"
},
"integrationFolder": "integration",
"specPattern": "**/*.spec.js"
}
Replace http://your-app-url with the URL of your application under test.
- Create a
.cypress/plugins/index.jsfile and add the following code to configure Cypress Cloud:
module.exports = (on, config) => {
on('before:browser:launch', (browser = {}, launchOptions) => {
if (browser.name === 'chrome') {
launchOptions.env = { ...launchOptions.env, CYPRESS_CLOUD: true };
}
return launchOptions;
});
};
- Commit your changes and push them to GitHub.
- In the Cypress Cloud dashboard, create a new project by connecting it to your GitHub repository.
Running Tests on Cypress Cloud
To run tests on Cypress Cloud:
- Install the
cypress-cloud-runnerpackage usingnpm install cypress-cloud-runner. - Update your test runner configuration in the
cypress.jsonfile to include the following:
{
"reporter": "cypress-mochawesome-reporter",
"reporterOptions": {
"reportDir": "cypress/reports/mocha",
"overwrite": false,
"html": false,
"json": true
},
"e2e": {
"setupFile": "./cypress/plugins/cloud-setup.js"
}
}
- Create a
cypress/plugins/cloud-setup.jsfile and add the following code to configure Cypress Cloud for running tests:
const { login as cloudLogin } = require('@cypress/cloud');
module.exports = (on, config) => {
on('before:browser:launch', async (browser = {}, launchOptions) => {
const env = process.env;
if (env.CYPRESS_CLOUD && env.CYPRESS_PROJECT_ID) {
await cloudLogin({
projectId: env.CYPRESS_PROJECT_ID,
username: env.CYPRESS_USERNAME,
password: env.CYPRESS_PASSWORD
});
}
return launchOptions;
});
};
- Replace
CYPRESS_PROJECT_ID,CYPRESS_USERNAME, andCYPRESS_PASSWORDwith your Cypress Cloud project credentials. - Add the following script to your
package.jsonfile:
"scripts": {
"test:cloud": "cypress run --record --key CYPRESS_PROJECT_KEY"
}
Replace CYPRESS_PROJECT_KEY with your Cypress Cloud project API key.
- Run tests on Cypress Cloud using the following command:
npm test:cloud
Worked Example
In this example, we will create a simple test for a login page and demonstrate how to configure Cypress Cloud to run it.
- Create an integration file named
login_spec.jsin thecypress/integrationfolder:
describe('Login', () => {
it('should log in successfully', () => {
cy.visit('/login');
cy.get('#username').type('testuser');
cy.get('#password').type('testpass');
cy.get('#submit-button').click();
cy.url().should('include', '/dashboard');
});
});
- Run the test locally using
npm run e2e. - Once the test is passing, configure Cypress Cloud as described in the previous section and run the test on Cypress Cloud using
npm test:cloud.
Common Mistakes
- Not configuring the
cypress.jsonfile correctly: Ensure that you have added the necessary configurations for your project, including the base URL, plugins, and reporters. - Incorrectly setting up Cypress Cloud credentials: Make sure to replace the placeholders in the
cypress/plugins/cloud-setup.jsfile with your actual Cypress Cloud project credentials. - Not committing and pushing changes to GitHub: Remember to commit and push your changes to GitHub before connecting your repository to Cypress Cloud.
- Using an incorrect API key: Double-check that you are using the correct API key for your Cypress Cloud project when running tests on Cypress Cloud.
- Not properly initializing the project with Cypress: Make sure to run
cypress initand navigate to the newly createdcypressfolder before configuring Cypress Cloud.
Practice Questions
- How can you configure Cypress Cloud to run tests on multiple machines?
- What is smart parallelization, and how does it help reduce CI spend?
- How can you use analytics in Cypress Cloud to track test health at the project and organization level?
- What are some benefits of using Cypress Cloud for managing your team's tests and application quality?
- How can you set up status checks from GitHub, GitLab, or Bitbucket to block failing code from merging?
FAQ
- Do I need to use the Cypress Cloud CLI to run tests on Cypress Cloud?
- Yes, you will need to install and configure the
cypress-cloud-runnerpackage to run your tests on Cypress Cloud.
- Can I use Cypress Cloud with any test runner other than Mochawesome?
- Yes, you can use other reporters like Allure or JUnit by configuring them in the
cypress.jsonfile.
- How do I manage flaky tests on Cypress Cloud?
- Cypress Cloud offers Flake Management features to help surface unreliable tests before your team starts ignoring real failures.
- Can I use Cypress Cloud with other test automation tools like Selenium or Playwright?
- No, Cypress Cloud is specifically designed for the Cypress testing framework. However, you can use it in conjunction with other end-to-end testing tools for comprehensive coverage of your application.
- Is there a limit to the number of tests I can run on Cypress Cloud?
- No, there are no limits on the number of tests you can run on Cypress Cloud as part of your free trial or paid subscription.