A Cypress test file typically includes describe
blocks (test suites) and it
blocks (individual tests).
describe('My First Test', () => {
it('Visits the Kitchen Sink', () => {
// Test steps go here
})
})
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.
A Cypress test file typically includes
|
|
Navigates to the specified URL.
|
|
Gets one or more DOM elements by selector.
|
|
Gets elements that contain the specified text.
|
|
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
|
|
Asserts that a DOM element has the expected state or value.
|
|
Uses Chai’s
|
|
Creates an alias for a DOM element that can be reused later.
|
|
Pauses execution for a specified amount of time (in milliseconds).
|
|
Waits for a specific route to be hit (useful for API testing).
|
Cypress simplifies form interactions. Use
|
Cypress Studio allows you to record interactions and generate Cypress tests. Enable it in
Then, right-click in the Cypress runner to start recording. |
You can create custom commands to encapsulate reusable logic. Add them to
Then use them in your tests:
|
Fixtures are used to load external data. Place your JSON data in the
|
The Cypress Runner provides a visual interface for running and debugging tests. It allows you to:
|
|
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.
|
Use
|
Use the Cypress Runner to inspect network requests. You can see the request headers, body, and response. For more advanced network request debugging, use |
|
The
|
You can set environment variables in
Access them in your tests:
|
Plugins extend Cypress’s functionality. Install plugins via npm or yarn and configure them in Common plugins include:
|