diff --git a/support/commands.js b/support/commands.js index 22fb5c2f6..5141fd66e 100644 --- a/support/commands.js +++ b/support/commands.js @@ -1,6 +1,23 @@ import '@testing-library/cypress/add-commands'; import 'cypress-wait-until'; +Cypress.Commands.add('getId', name => { + if (name.includes('@')) { + return cy.get(`${name}`); + } + return cy.get(`[data-testid="${name}"]`).as(name); +}); + +Cypress.Commands.add('getText', selector => { + return cy.getId(`${selector}`).invoke('text'); +}); + +Cypress.Commands.add('waitUntilExist', selector => { + cy.waitUntil(() => { + return cy.getId(`${selector}`).should('exist'); + }); +}); + Cypress.Commands.add('getDesktopSizes', () => { return [ [1366, 768], diff --git a/support/index.d.ts b/support/index.d.ts index 856bc2ad0..5336ad5c0 100644 --- a/support/index.d.ts +++ b/support/index.d.ts @@ -1,5 +1,26 @@ declare namespace Cypress { interface Chainable { + /** + * Get element using data-testid and sets an alias for it + * @example + * cy.getId('dataTestId') + * cy.getId('alias') + */ + getId(testid: string): Chainable; + /** + * Get text of element + * @example + * cy.getText('selector').then(text => cy.log(text)) + * cy.getText('alias').then(text => cy.log(text)) + */ + getText(selector: string): Chainable; + /** + * Waits until element exists + * @example + * cy.waitUntilExist('selector') + * cy.waitUntilExist('alias') + */ + waitUntilExist(selector: string): Chainable; /** * Get the most popular desktop resolutions * @example