Skip to content

Cypress Cheat Sheet

This cheat sheet condenses the entire course into a single, fast-scanning reference. Use it while coding to quickly recall syntax without reopening each individual lesson.

How to Use This Cheat Sheet

Each table below covers one area of Cypress, matching the order of lessons in this course, so you can jump straight to the syntax you need without re-reading full explanations.

For the reasoning and deeper context behind any entry, revisit that topic's dedicated lesson earlier in this course.

cy.visit('/path')             // navigate
cy.get('[data-cy="x"]')       // locate
.should('be.visible')         // assert
.click() / .type('text')      // interact

These four lines cover the majority of everyday Cypress test structure.

Quick Project Commands

npm install cypress --save-dev
npx cypress open
npx cypress run
npx cypress run --spec "cypress/e2e/login.cy.js"
  • cypress open launches the interactive Test Runner for writing and debugging.
  • cypress run executes tests headlessly, typically used in CI.
  • --spec targets a specific file or glob pattern of files.
  • See the tables below for deeper syntax across every major Cypress feature.

Core Commands Reference

The commands used in nearly every Cypress test.

Command Example Purpose
Visit cy.visit('/login') Load a page
Get cy.get('[data-cy="x"]') Locate elements
Find cy.get(x).find(y) Locate descendants
Contains cy.contains('Save') Locate by text
Click .click() Simulate a click
Type .type('text') Simulate typing
Should .should('be.visible') Implicit, retried assertion
Then .then(($el) => {...}) Work with a resolved subject

Assertions Reference

Assertion Example
Existence .should('exist') / .should('not.exist')
Visibility .should('be.visible') / .should('be.hidden')
Text .should('have.text', 'x') / .should('contain', 'x')
Class .should('have.class', 'x')
Attribute .should('have.attr', 'href', '/x')
Length .should('have.length', 3)
Value .should('have.value', 'x')
Checked .should('be.checked')
Disabled .should('be.disabled')
URL cy.url().should('include', '/x')

Network Testing Reference

Purpose Example
Stub with a fixture cy.intercept('GET', '/api/x', { fixture: 'x.json' })
Stub inline cy.intercept('GET', '/api/x', { body: [] })
Stub status code cy.intercept('GET', '/api/x', { statusCode: 500 })
Spy only cy.intercept('POST', '/api/x').as('post')
Wait for it cy.wait('@post')
Direct request cy.request('GET', '/api/x')

Custom Commands and Sessions Reference

Purpose Example
Define a command Cypress.Commands.add('login', fn)
Overwrite a command Cypress.Commands.overwrite('type', fn)
Cache a login cy.session(id, setupFn)
Stub a function cy.stub().as('name')
Spy on a function cy.spy(obj, 'method').as('name')
Load a fixture cy.fixture('data.json')

Configuration Reference

Setting Example
Base URL baseUrl: 'http://localhost:3000'
Default timeout defaultCommandTimeout: 6000
Retries retries: { runMode: 2, openMode: 0 }
Env variable Cypress.env('apiUrl')
Spec pattern specPattern: 'cypress/e2e/**/*.cy.js'

Common Mistakes

  • Treating this cheat sheet as a substitute for understanding the reasoning in each topic's dedicated lesson.
  • Copying syntax without checking whether it fits your project's actual Cypress version and setup.
  • Skipping the deeper lesson when a cheat sheet entry doesn't fully make sense in context.
  • Not revisiting this page periodically as your own project's conventions evolve.

Key Takeaways

  • This cheat sheet condenses commands, assertions, network testing, custom commands, and configuration into quick reference tables.
  • Each entry maps to a deeper lesson earlier in this course for full context and reasoning.
  • Prefer .should()-based assertions and cy.intercept()-based network control as defaults.
  • Use this page as an ongoing quick reference while building real Cypress suites.

Pro Tip

Bookmark this cheat sheet page specifically, of everything in this course, it's the page you'll likely return to most often once you're comfortable with the underlying concepts and just need a fast syntax reminder.