Skip to content

Instantly share code, notes, and snippets.

@gioragutt
Created August 9, 2021 12:55
  • Select an option

Select an option

Revisions

  1. gioragutt created this gist Aug 9, 2021.
    17 changes: 17 additions & 0 deletions cypress-tid-selector.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    declare namespace Cypress {
    interface Chainable {
    tid: Cypress.Chainable['get'];
    }
    }

    function attributeSelector(key: string, value: string) {
    return `[${key}=${value}]`;
    }

    function tidSelector(testId: string) {
    return attributeSelector('data-test-id', testId);
    }

    Cypress.Commands.add('tid', (testId: string, options?: Parameters<Cypress.Chainable['tid']>[1]) => {
    return cy.get(tidSelector(testId), options);
    });