Last active
May 13, 2022 22:33
-
-
Save ShanonJackson/1f0084c97c94ef547a7d8ee8c3ca62d6 to your computer and use it in GitHub Desktop.
Cypress tips.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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