Cypress Guide
CypressEnd-to-End Testing
Learn browser automation, time-travel debugging, and writing reliable end-to-end tests with Cypress.
Contents
Cypress Basics
Cypress is a JavaScript end-to-end testing framework. It runs in the browser and provides time-travel debugging.
bash
# Installation
npm install --save-dev cypress
# Open Cypress
npx cypress open
# Run headless
npx cypress runjavascript
// Basic Test (cypress/e2e/example.cy.js)
describe('Login Page', () => {
it('should login successfully', () => {
cy.visit('/login');
cy.get('[data-cy=email]').type('user@example.com');
cy.get('[data-cy=password]').type('password123');
cy.get('[data-cy=submit]').click();
cy.url().should('include', '/dashboard');
});
});
// Visit a page
cy.visit('https://example.com');
// Query elements
cy.get('button');
cy.get('.class-name');
cy.get('#id');
cy.get('[data-cy=submit]'); // Recommended