Skip to content

Commit 5547101

Browse files
authored
Playwright: fix (hopefully) flaky shields test (#28641)
* Playwright: improve failure report when an unexpected shield exists If we discover an E2E shield when we didn't expect one, let's make the error message more helpful by checking the tooltip. * Playwright: fix (hopefully) flaky shields test Wait for our user to fetch the bot's identity before running the test, to work around a race in the shield logic. Hopefully, fixes #28061
1 parent 085854b commit 5547101

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

playwright/e2e/crypto/event-shields.spec.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
66
Please see LICENSE files in the repository root for full details.
77
*/
88

9+
import { Locator } from "@playwright/test";
10+
911
import { expect, test } from "../../element-web-test";
1012
import {
1113
autoJoin,
@@ -17,6 +19,7 @@ import {
1719
verify,
1820
} from "./utils";
1921
import { bootstrapCrossSigningForClient } from "../../pages/client.ts";
22+
import { ElementAppPage } from "../../pages/ElementAppPage.ts";
2023

2124
test.describe("Cryptography", function () {
2225
test.use({
@@ -277,6 +280,15 @@ test.describe("Cryptography", function () {
277280
bot: bob,
278281
homeserver,
279282
}) => {
283+
// Workaround for https://github.com/element-hq/element-web/issues/28640:
284+
// make sure that Alice has seen Bob's identity before she goes offline. We do this by opening
285+
// his user info.
286+
await app.toggleRoomInfoPanel();
287+
const rightPanel = page.locator(".mx_RightPanel");
288+
await rightPanel.getByRole("menuitem", { name: "People" }).click();
289+
await rightPanel.getByRole("button", { name: bob.credentials!.userId }).click();
290+
await expect(rightPanel.locator(".mx_UserInfo_devices")).toContainText("1 session");
291+
280292
// Our app is blocked from syncing while Bob sends his messages.
281293
await app.client.network.goOffline();
282294

@@ -306,7 +318,7 @@ test.describe("Cryptography", function () {
306318
);
307319

308320
const penultimate = page.locator(".mx_EventTile").filter({ hasText: "test encrypted from verified" });
309-
await expect(penultimate.locator(".mx_EventTile_e2eIcon")).not.toBeVisible();
321+
await assertNoE2EIcon(penultimate, app);
310322
});
311323

312324
test("should show correct shields on events sent by users with changed identity", async ({
@@ -335,3 +347,21 @@ test.describe("Cryptography", function () {
335347
});
336348
});
337349
});
350+
351+
/**
352+
* Check that the given message doesn't have an E2E warning icon.
353+
*
354+
* If it does, throw an error.
355+
*/
356+
async function assertNoE2EIcon(messageLocator: Locator, app: ElementAppPage) {
357+
// Make sure the message itself exists, before we check if it has any icons
358+
await messageLocator.waitFor();
359+
360+
const e2eIcon = messageLocator.locator(".mx_EventTile_e2eIcon");
361+
if ((await e2eIcon.count()) > 0) {
362+
// uh-oh, there is an e2e icon. Let's find out what it's about so that we can throw a helpful error.
363+
await e2eIcon.focus();
364+
const tooltip = await app.getTooltipForElement(e2eIcon);
365+
throw new Error(`Found an unexpected e2eIcon with tooltip '${await tooltip.textContent()}'`);
366+
}
367+
}

0 commit comments

Comments
 (0)