From 2acf78a9e4bab91cd39dc2670953e44257747d04 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 13 Jan 2023 10:25:50 +0000 Subject: [PATCH] Fix unstable cypress test --- cypress/e2e/integration-manager/kick.spec.ts | 22 ++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/cypress/e2e/integration-manager/kick.spec.ts b/cypress/e2e/integration-manager/kick.spec.ts index 2cd66fa51b..79e1db1ef9 100644 --- a/cypress/e2e/integration-manager/kick.spec.ts +++ b/cypress/e2e/integration-manager/kick.spec.ts @@ -82,9 +82,27 @@ function sendActionFromIntegrationManager(integrationManagerUrl: string, targetR }); } +function clickUntilGone(selector: string, attempt = 0) { + if (attempt === 11) { + throw new Error("clickUntilGone attempt count exceeded"); + } + + cy.get(selector) + .last() + .click() + .then(($button) => { + const exists = Cypress.$(selector).length > 0; + if (exists) { + clickUntilGone(selector, ++attempt); + } + }); +} + function expectKickedMessage(shouldExist: boolean) { - // Expand any event summaries - cy.get(".mx_GenericEventListSummary_toggle[aria-expanded=false]").click({ multiple: true }); + // Expand any event summaries, we can't use a click multiple here because clicking one might de-render others + // This is quite horrible but seems the most stable way of clicking 0-N buttons, + // one at a time with a full re-evaluation after each click + clickUntilGone(".mx_GenericEventListSummary_toggle[aria-expanded=false]"); // Check for the event message (or lack thereof) cy.contains(".mx_EventTile_line", `${USER_DISPLAY_NAME} removed ${BOT_DISPLAY_NAME}: ${KICK_REASON}`).should(