Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new custom commands #4

Merged
merged 3 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions support/commands.js
Original file line number Diff line number Diff line change
@@ -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],
Expand Down
21 changes: 21 additions & 0 deletions support/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
declare namespace Cypress {
interface Chainable<Subject> {
/**
* Get element using data-testid and sets an alias for it
* @example
* cy.getId('dataTestId')
* cy.getId('alias')
*/
getId(testid: string): Chainable<Subject>;
/**
* 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<Subject>;
/**
* Waits until element exists
* @example
* cy.waitUntilExist('selector')
* cy.waitUntilExist('alias')
*/
waitUntilExist(selector: string): Chainable<Subject>;
/**
* Get the most popular desktop resolutions
* @example
Expand Down