Cypress Cheat Sheet

Quick reference for Cypress end-to-end testing commands. Selectors, assertions, network stubbing, and best practices for reliable browser tests.

Getting Started Selectors Actions Assertions Network & Stubs

Getting Started

npx cypress open Open the Cypress Test Runner GUI
npx cypress run Run all tests headlessly in the terminal
npx cypress run --spec "cypress/e2e/login.cy.js" Run a specific test file
cy.visit("https://example.com") Navigate to a URL
cy.reload() Reload the current page

Selectors

cy.get("button.submit") Select elements by CSS selector
cy.contains("Submit") Select element containing text
cy.find(".child") Find descendant elements within a subject
cy.first() / cy.last() Get the first or last element in a set
cy.get('[data-testid="login-btn"]') Select by data-testid attribute (recommended)

Actions

.click() Click an element
.type("[email protected]") Type text into an input field
.clear() Clear the value of an input or textarea
.check() / .uncheck() Check or uncheck a checkbox/radio
.select("option-value") Select an option from a dropdown

Assertions

.should("be.visible") Assert element is visible on the page
.should("have.text", "Hello") Assert element has exact text content
.should("have.length", 3) Assert number of matched elements
.should("contain", "Welcome") Assert element contains text
.should("exist") / .should("not.exist") Assert element exists or does not exist

Network & Stubs

cy.intercept("GET", "/api/users", { body: [] }) Stub a network request with a response
cy.wait("@getUsers") Wait for an aliased intercept to complete
cy.request("GET", "/api/health") Make a real HTTP request (bypasses UI)
cy.fixture("users.json") Load test data from cypress/fixtures/
cy.clock() / cy.tick(1000) Control time: freeze the clock and advance by ms

Try It Live

Test these patterns with our free API Tester. No signup needed.

Open API Tester →
Step-by-Step Guide

How to Test an API Online

Read Guide →

More Cheat Sheets