Skip to content

Instantly share code, notes, and snippets.

@ShanonJackson
Last active May 13, 2022 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShanonJackson/1f0084c97c94ef547a7d8ee8c3ca62d6 to your computer and use it in GitHub Desktop.
Save ShanonJackson/1f0084c97c94ef547a7d8ee8c3ca62d6 to your computer and use it in GitHub Desktop.
Cypress tips.
Cypress.Commands.add('cid', (id) => cy.get(`[data-cy='${id}']`)); // shorthand for find by data-cy='ID' (cypress id)
Cypress.Commands.add('pclass', (cls: string) => cy.get(`[class^='${cls}']`)); // shorthand for find by partial class
// This is your priority order for finding an element.
// find by cypress id > find by text > find by partial class > nested selectors
// don't because the surface area for any change to break your "selector" is very large for each additional selector.
cy.get(':nth-child(2) > :nth-child(2) > .inputmodule_input__3wsvS').type('foo');
// do
cy.pclass('inputmodule_input').type('foo');
// or if multiple
cy.pclass('inputmodule_input').eq(1).type('foo');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment