declare namespace Cypress { interface Chainable { getByCypressId ( id ) : Chainable < Element > ; findByCypressId ( id ) : Chainable < Element > ; } } const CYPRESS_ATTR = 'data-cypress-id' ; Cypress . Commands . add ( 'getByCypressId' , ( id ) => { return cy . get ( `[${ CYPRESS_ATTR }="${ id }"]` ) ; } ) ; Cypress . Commands . add ( 'findByCypressId' , { prevSubject : 'element' } , ( parent , id ) => { return cy . wrap ( parent ) . find ( `[${ CYPRESS_ATTR }="${ id }"]` ) ; } ) ;