diff --git a/support/commands.js b/support/commands.js index e56b6df38..674741691 100644 --- a/support/commands.js +++ b/support/commands.js @@ -7,6 +7,11 @@ Cypress.Commands.add('getId', name => { } return cy.get(`[data-testid="${name}"]`).as(name); }); + +Cypress.Commands.add('getText', selector => { + return cy.getId(`${selector}`).invoke('text'); +}); + Cypress.Commands.add('getDesktopSizes', () => { return [ [1366, 768], diff --git a/support/index.d.ts b/support/index.d.ts index d54a51ef7..c32a6eb31 100644 --- a/support/index.d.ts +++ b/support/index.d.ts @@ -7,6 +7,13 @@ declare namespace Cypress { * 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; /** * Get the most popular desktop resolutions * @example