From eced103458e2d4141d63c2787b7a9de07ab24ce9 Mon Sep 17 00:00:00 2001 From: Kerry Date: Sat, 15 Jul 2023 01:28:22 +1200 Subject: [PATCH] Fix: cypress `findByTestId` and `percySnapshotElement` do not work together (#10947) * check for testid in percySnapshotElement * Update percy.ts --------- Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> --- cypress/support/percy.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cypress/support/percy.ts b/cypress/support/percy.ts index ae35248789b..0b2c10c90ec 100644 --- a/cypress/support/percy.ts +++ b/cypress/support/percy.ts @@ -47,8 +47,15 @@ Cypress.Commands.add("percySnapshotElement", { prevSubject: "element" }, (subjec // Await inline spinners to vanish cy.get(".mx_InlineSpinner", { log: false }).should("not.exist"); } + + let selector = subject.selector; + // cy.findByTestId sets the selector to `findByTestId()` + // which is not usable as a scope + if (selector.startsWith("findByTestId")) { + selector = `[data-testid="${subject.attr("data-testid")}"]`; + } cy.percySnapshot(name, { - domTransformation: (documentClone) => scope(documentClone, subject.selector), + domTransformation: (documentClone) => scope(documentClone, selector), ...options, }); });