Cheat sheets / Cypress
Cypress
Command queue, retries, intercepts, and the limits interviewers probe.
How it works
- Command queue
- Commands are queued and run asynchronously; do not treat them as returning values.
- Retry-ability
- Queries and assertions retry until timeout. Chain the assertion to the query to benefit.
- Runs in the browser
- Same run loop as the app, which gives speed and access to the app, with limits on multi-tab and multi-origin work.
Everyday commands
- Select and assert
- Prefer data attributes.
- Intercept
- Spy on or stub network calls and wait for them by alias.
- Custom commands
- Wrap repeated flows like login.
- cy.session
- Caches and restores login state across tests.
cy.get('[data-cy=submit]').click(); cy.contains('Saved').should('be.visible');cy.intercept('GET', '/api/items').as('items'); cy.wait('@items');Cypress.Commands.add('login', (u, p) => { /* ... */ });Known limits
- Multiple tabs
- Not supported; stub window.open or test the target separately.
- Cross-origin
- Use cy.origin for flows that leave the first origin.
- Browsers
- Chromium family, Firefox and WebKit (experimental); check current support before claiming coverage.