Testing is a communication tool. The end-to-end test is the best way to express what the user flow should be. The test author communicates with the machine the test steps, but also communicates with other developers what the user is expected to do and see. I love clear tests and use a lot of log messages in my tests. Recently I have been using the plugin cypress-plugin-steps that makes the communication much clearer.
This plugin is simple to install:
npm i -D cypress-plugin-steps
- add the
import 'cypress-plugin-steps'
line to your specs / support file
The plugin provides 3 commands: cy.section
, cy.step
, and the new command cy.todo
. Each command takes a string argument: the message to print. Let's try a simple test:
1 | it("edits a task", () => { |
I hid the intermediate commands in the test above, yet you should get a general idea of what is going on. Now let's look at the UI these custom commands are rendering in Cypress Command Log by injecting their own CSS styles:
Eye-catching, right?
In addition to making the logical test steps pop, the plugin provides value when the test fails. I have changed the expected number of elements to make the test fail. Look at the error message: it includes the list of sections and steps that finished before the failure!
When the error fails the message includes the steps
Nice! If you want to see this plugin cypress-plugin-steps in action, check out the video below.
Follow the plugin's author Filip Hric
PS: The demo application used in this blog post is an example from my new course in progress Cursor AI For Cypress Testing.