Skip to content

Commit f94b456

Browse files
committed
In lifecycle tests, dismiss the Verify toast if it appears
1 parent 1aa840c commit f94b456

2 files changed

Lines changed: 43 additions & 3 deletions

File tree

modules/widget-lifecycle/element-web/e2e/widget-lifecycle.spec.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ test.describe("Widget Lifecycle", () => {
6363
},
6464
});
6565

66-
test("auto-approves preload and identity", async ({ page, user, homeserver }, testInfo) => {
66+
test("auto-approves preload and identity", async ({ page, user, homeserver, toasts }, testInfo) => {
67+
toasts.rejectToastIfExists("Verify this device");
68+
6769
// A bot creates a room with the widget pinned to the top panel, then invites the test user.
6870
// Because the widget was added by a different user (the bot), Element would normally show a
6971
// preload consent dialog before loading it — this test verifies that dialog is skipped.
@@ -119,7 +121,9 @@ test.describe("Widget Lifecycle", () => {
119121
).toBeVisible();
120122
});
121123

122-
test("prompts for capabilities not in the allowlist", async ({ page, user, homeserver }, testInfo) => {
124+
test("prompts for capabilities not in the allowlist", async ({ page, user, homeserver, toasts }, testInfo) => {
125+
toasts.rejectToastIfExists("Verify this device");
126+
123127
const bot = await homeserver.registerUser(`bot_${testInfo.testId}`, "password", "Bot");
124128
const { room_id: roomId } = await homeserver.csApi.request<{ room_id: string }>(
125129
"POST",
@@ -180,7 +184,10 @@ test.describe("Widget Lifecycle", () => {
180184
page,
181185
user,
182186
homeserver,
187+
toasts,
183188
}, testInfo) => {
189+
toasts.rejectToastIfExists("Verify this device");
190+
184191
const bot = await homeserver.registerUser(`bot_${testInfo.testId}`, "password", "Bot");
185192
const { room_id: roomId } = await homeserver.csApi.request<{ room_id: string }>(
186193
"POST",

playwright/element-web-test.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ Please see LICENSE files in the repository root for full details.
66
*/
77

88
import { test as base, expect, type TestFixtures } from "@element-hq/element-web-playwright-common";
9+
import { Locator, Page } from "@playwright/test";
910

1011
export interface Options {
1112
moduleDir: string;
1213
modules: string[];
1314
}
1415

15-
export const test = base.extend<TestFixtures & Options>({
16+
export const test = base.extend<TestFixtures & Options & { toasts: Toasts }>({
1617
moduleDir: ["", { option: true }],
1718
modules: async ({ moduleDir }, use) => {
1819
await use([`${moduleDir}/lib/index.js`]);
@@ -30,6 +31,38 @@ export const test = base.extend<TestFixtures & Options>({
3031

3132
await use(page);
3233
},
34+
35+
toasts: async ({ page }, use) => {
36+
await use(new Toasts(page));
37+
},
3338
});
3439

3540
export { expect };
41+
42+
class Toasts {
43+
public constructor(private readonly page: Page) {}
44+
45+
/**
46+
* Find a toast with the given title, if it exists.
47+
*
48+
* @param title - title of the toast.
49+
* @returns the Locator for the matching toast, or an empty locator if it
50+
* doesn't exist.
51+
*/
52+
public getToastIfExists(title: string): Locator {
53+
return this.page.locator(".mx_Toast_toast", { hasText: title }).first();
54+
}
55+
56+
/**
57+
* Reject a toast with the given title, if it exists. Only works for the
58+
* first toast in the stack.
59+
*
60+
* @param title - title of the toast
61+
*/
62+
public async rejectToastIfExists(title: string): Promise<void> {
63+
const toast = this.getToastIfExists(title).locator('.mx_Toast_buttons button[data-kind="secondary"]');
64+
if ((await toast.count()) > 0) {
65+
await toast.click();
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)