Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Fix flaky alerts toggle e2e in sdk iframe embed setup select-embed-options (#78285)

github-automation-metabase1081fb8c0293
diff --git a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/select-embed-options.cy.spec.ts b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/select-embed-options.cy.spec.ts
index 13a6cb9b385..1ff974336a9 100644
--- a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/select-embed-options.cy.spec.ts
+++ b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/select-embed-options.cy.spec.ts
@@ -17,6 +17,12 @@ const { PRODUCTS, PRODUCTS_ID } = SAMPLE_DATABASE;
const DASHBOARD_NAME = "Orders in a dashboard";
const QUESTION_NAME = "Orders, Count";
+// Toggling a sidebar option re-renders (and re-runs the query of) the embedded
+// question inside the already-loaded preview iframe. That round-trip can exceed
+// Cypress's default 4s command timeout, so lookups that depend on the re-render
+// finishing get a longer budget to wait it out.
+const RERENDER_TIMEOUT = 15000;
+
const suiteTitle =
"scenarios > embedding > sdk iframe embed setup > select embed options";
@@ -641,7 +647,7 @@ describe(suiteTitle, () => {
cy.log("assert that alert button appears in preview");
H.getSimpleEmbedIframeContent()
- .findByRole("button", { name: "Alerts" })
+ .findByRole("button", { name: "Alerts", timeout: RERENDER_TIMEOUT })
.should("be.visible");
cy.log(
@@ -653,18 +659,31 @@ describe(suiteTitle, () => {
.click()
.should("not.be.checked");
H.getSimpleEmbedIframeContent()
- .findByRole("button", { name: "Alerts" })
+ .findByRole("button", { name: "Alerts", timeout: RERENDER_TIMEOUT })
.should("be.visible");
cy.log("assert that unchecking alerts will close the alert modal");
const newAlertModalTitle = "New alert";
- H.getSimpleEmbedIframeContent().within(() => {
- cy.findByRole("button", { name: "Alerts" }).should("be.visible").click();
-
- cy.findByRole("heading", { name: newAlertModalTitle }).should(
- "be.visible",
- );
- });
+ // Re-query the iframe body for the click instead of caching it via
+ // within(): toggling the sidebar options above re-renders the embedded
+ // question, so a cached body (and the element found inside it) goes stale
+ // and the "Alerts" ActionIcon detaches mid-click. Asserting visibility and
+ // clicking as separate re-queried chains lets Cypress re-run the full query
+ // for the action and land on a freshly-attached, stable button. The re-render
+ // re-executes the question's query inside the already-loaded iframe, which can
+ // exceed the default 4s command timeout, so give these lookups a longer budget.
+ H.getSimpleEmbedIframeContent()
+ .findByRole("button", { name: "Alerts", timeout: RERENDER_TIMEOUT })
+ .should("be.visible");
+ H.getSimpleEmbedIframeContent()
+ .findByRole("button", { name: "Alerts", timeout: RERENDER_TIMEOUT })
+ .click();
+ H.getSimpleEmbedIframeContent()
+ .findByRole("heading", {
+ name: newAlertModalTitle,
+ timeout: RERENDER_TIMEOUT,
+ })
+ .should("be.visible");
getEmbedSidebar()
.findByLabelText("Allow alerts")