Cypress | Sheetly Cheat Sheet

Last Updated: November 21, 2025

Cypress

Modern end-to-end testing framework

Installation & Setup

npm install cypress --save-dev
Install Cypress
npx cypress open
Open Cypress Test Runner
npx cypress run
Run tests headlessly
npx cypress run --spec 'path/to/spec.cy.js'
Run specific test

Basic Test Structure

describe('My Test Suite', () => {
  beforeEach(() => {
    cy.visit('https://example.com');
  });

  it('should display the homepage', () => {
    cy.get('h1').should('contain', 'Welcome');
  });

  it('should navigate to about page', () => {
    cy.get('a[href="/about"]').click();
    cy.url().should('include', '/about');
  });
});

Common Commands

Item Description
cy.visit(url) Navigate to URL
cy.get(selector) Get DOM element
cy.contains(text) Find element with text
cy.click() Click element
cy.type(text) Type into input
cy.should(assertion) Assert condition
cy.wait(ms) Wait for time/alias
cy.intercept() Stub network requests

Assertions

// Existence
cy.get('.btn').should('exist');
cy.get('.modal').should('not.exist');

// Visibility
cy.get('.banner').should('be.visible');

// Text content
cy.get('h1').should('have.text', 'Title');
cy.get('p').should('contain', 'substring');

// Attributes
cy.get('button').should('have.class', 'active');
cy.get('input').should('have.value', 'test');

// Length
cy.get('li').should('have.length', 5);

Intercept Network Requests

// Stub response
cy.intercept('GET', '/api/users', { fixture: 'users.json' });

// Wait for request
cy.intercept('POST', '/api/login').as('loginRequest');
cy.get('button').click();
cy.wait('@loginRequest');

// Assert on request
cy.wait('@loginRequest').its('request.body')
  .should('have.property', 'username');

💡 Pro Tips

Quick Reference

Use cy.debug() to pause test execution and inspect

← Back to Data Science & ML | Browse all categories | View all cheat sheets