From 86d400e2ffce759852b7ad69f6c12f370758d597 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Tue, 1 Dec 2020 22:29:19 +0100 Subject: [PATCH 1/3] feat: add getId command Signed-off-by: Jakub Mucha --- support/commands.js | 6 ++++++ support/index.d.ts | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/support/commands.js b/support/commands.js index 22fb5c2f6..e56b6df38 100644 --- a/support/commands.js +++ b/support/commands.js @@ -1,6 +1,12 @@ 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('getDesktopSizes', () => { return [ [1366, 768], diff --git a/support/index.d.ts b/support/index.d.ts index 856bc2ad0..d54a51ef7 100644 --- a/support/index.d.ts +++ b/support/index.d.ts @@ -1,5 +1,12 @@ 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 the most popular desktop resolutions * @example From 487052126bb173662ace9e75461334c050ae899a Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Tue, 1 Dec 2020 22:29:40 +0100 Subject: [PATCH 2/3] feat: add getText command Signed-off-by: Jakub Mucha --- support/commands.js | 5 +++++ support/index.d.ts | 7 +++++++ 2 files changed, 12 insertions(+) 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 From 3304ad1bd2220f285d1f521c3d34dfe2defb1ba0 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Tue, 1 Dec 2020 22:29:54 +0100 Subject: [PATCH 3/3] feat: add waitUntilExist command Signed-off-by: Jakub Mucha --- support/commands.js | 6 ++++++ support/index.d.ts | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/support/commands.js b/support/commands.js index 674741691..5141fd66e 100644 --- a/support/commands.js +++ b/support/commands.js @@ -12,6 +12,12 @@ 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 c32a6eb31..5336ad5c0 100644 --- a/support/index.d.ts +++ b/support/index.d.ts @@ -14,6 +14,13 @@ declare namespace Cypress { * 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