Create Custom Cypress Commands

InstructorBrett Cassette

Share this video with your friends

Send Tweet

Do you need to reuse complex Cypress calls often (like when accessing the store)?

You can turn them into custom Cypress commands, and even customize their output in the time-traveling debugger, so it's easy to see a snapshot at the point your command ran!

Recommended Homework:

  • Review the Best Practices for Custom Commands - https://docs.cypress.io/api/cypress-api/custom-commands.html#Best-Practices
Eric Laursen
~ 5 years ago

I'm having trouble coding-along with the video @ 2:03 :( In short, 'store' is not showing in my cypress runner output window when the video says 'store' is logging. In the video, the last piece of code that is updated is the 'command', and my code matches the video's: Cypress.Commands.add('store', (str = '') => { const log = Cypress.log({ name: 'store' }); return cy .window({ log: false }) .then((win) => win.store.getState()); });

The next thing in the video is that 'store' shows in the runner output replacing 'window' in the runner output. Here, though, 'window' still remains showing in my case.