Catalog / Cypress Testing Cheatsheet
Cypress Testing Cheatsheet
A quick reference guide for writing and debugging Cypress tests. This cheat sheet covers essential commands, selectors, assertions, and debugging techniques to help you create robust and reliable end-to-end tests.
Core Concepts & Commands
Basic Structure
A Cypress test file typically includes
|
Visiting a Page
|
Navigates to the specified URL.
|
Finding Elements
|
Gets one or more DOM elements by selector.
|
|
Gets elements that contain the specified text.
|
Interacting with Elements
|
Clicks a DOM element.
|
|
Types into a DOM element.
|
|
Clears the value of an input or textarea.
|
|
Checks or unchecks a checkbox or radio button.
|
|
Selects an option in a
|
Assertions
|
Asserts that a DOM element has the expected state or value.
|
|
Uses Chai’s
|
Advanced Commands & Concepts
Aliases
|
Creates an alias for a DOM element that can be reused later.
|
Waiting
|
Pauses execution for a specified amount of time (in milliseconds).
|
|
Waits for a specific route to be hit (useful for API testing).
|
Working with Forms
Cypress simplifies form interactions. Use
|
Cypress Studio
Cypress Studio allows you to record interactions and generate Cypress tests. Enable it in
Then, right-click in the Cypress runner to start recording. |
Custom Commands
You can create custom commands to encapsulate reusable logic. Add them to
Then use them in your tests:
|
Using Fixtures
Fixtures are used to load external data. Place your JSON data in the
|
Debugging Techniques
Using the Cypress Runner
The Cypress Runner provides a visual interface for running and debugging tests. It allows you to:
|
Debugging Commands
|
Inserts a
|
|
Pauses the test execution, allowing you to inspect the current state in the Cypress Runner.
|
|
Log the output to the console, for debugging purposes.
|
Console Logging
Use
|
Network Request Logging
Use the Cypress Runner to inspect network requests. You can see the request headers, body, and response. For more advanced network request debugging, use |
Common Errors
|
Configuration
cypress.config.js
The
|
Environment Variables
You can set environment variables in
Access them in your tests:
|
Plugins
Plugins extend Cypress’s functionality. Install plugins via npm or yarn and configure them in Common plugins include:
|