From 90ba56c1ced5840b09f181f2bdf986d292d1887e Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 20 May 2026 15:26:08 +0100 Subject: [PATCH] Make viewRoomByName dismiss toasts on each retry (#33542) Otherwise it can just race, as per comment --- apps/web/playwright/pages/ElementAppPage.ts | 32 +++++++++++++++------ 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/apps/web/playwright/pages/ElementAppPage.ts b/apps/web/playwright/pages/ElementAppPage.ts index 62e9df90c9..c657b6fe93 100644 --- a/apps/web/playwright/pages/ElementAppPage.ts +++ b/apps/web/playwright/pages/ElementAppPage.ts @@ -100,15 +100,31 @@ export class ElementAppPage { // otherwise we may race with page loading await this.page.getByTestId("room-list").waitFor(); - await rejectToastIfExists(this.page, "Verify this device", { timeout: 50 }); - const keyStorageToastRejected = await rejectToastIfExists(this.page, "Turn on key storage", { timeout: 50 }); - if (keyStorageToastRejected) { - await this.page.getByRole("button", { name: "Yes, dismiss" }).click(); - } - await rejectToastIfExists(this.page, "Notifications", { timeout: 50 }); + const dismissToasts = async (): Promise => { + await rejectToastIfExists(this.page, "Verify this device", { timeout: 50 }); + const keyStorageToastRejected = await rejectToastIfExists(this.page, "Turn on key storage", { + timeout: 50, + }); + if (keyStorageToastRejected) { + await this.page.getByRole("button", { name: "Yes, dismiss" }).click(); + } + await rejectToastIfExists(this.page, "Notifications", { timeout: 50 }); + }; - // We get the room list by test-id which is a listbox and matching title=name - return this.page.getByTestId("room-list").locator(`[title="${name}"]`).first().click(); + await dismissToasts(); + + // We get the room list by test-id which is a listbox and matching title=name. + // Retry, closing toasts each time, as otherwise it can race and the toast can appear after we try to close them + const roomTile = this.page.getByTestId("room-list").locator(`[title="${name}"]`).first(); + for (let attemptsLeft = 10; attemptsLeft > 0; attemptsLeft--) { + try { + await roomTile.click({ timeout: 500 }); + return; + } catch (e) { + if (attemptsLeft === 1) throw e; + await dismissToasts(); + } + } } /**