From 33c69c32f7bead34558380b6863fb8e0bc0c7c4f Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 4 Dec 2024 21:31:50 +0000 Subject: [PATCH 1/2] 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/e2e/crypto/event-shields.spec.ts | 23 ++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/playwright/e2e/crypto/event-shields.spec.ts b/playwright/e2e/crypto/event-shields.spec.ts index c6382f1d726..84b908bf6d1 100644 --- a/playwright/e2e/crypto/event-shields.spec.ts +++ b/playwright/e2e/crypto/event-shields.spec.ts @@ -6,6 +6,8 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only Please see LICENSE files in the repository root for full details. */ +import { Locator } from "@playwright/test"; + import { expect, test } from "../../element-web-test"; import { autoJoin, @@ -17,6 +19,7 @@ import { verify, } from "./utils"; import { bootstrapCrossSigningForClient } from "../../pages/client.ts"; +import { ElementAppPage } from "../../pages/ElementAppPage.ts"; test.describe("Cryptography", function () { test.use({ @@ -306,7 +309,7 @@ test.describe("Cryptography", function () { ); const penultimate = page.locator(".mx_EventTile").filter({ hasText: "test encrypted from verified" }); - await expect(penultimate.locator(".mx_EventTile_e2eIcon")).not.toBeVisible(); + await assertNoE2EIcon(penultimate, app); }); test("should show correct shields on events sent by users with changed identity", async ({ @@ -335,3 +338,21 @@ test.describe("Cryptography", function () { }); }); }); + +/** + * Check that the given message doesn't have an E2E warning icon. + * + * If it does, throw an error. + */ +async function assertNoE2EIcon(messageLocator: Locator, app: ElementAppPage) { + // Make sure the message itself exists, before we check if it has any icons + await messageLocator.waitFor(); + + const e2eIcon = messageLocator.locator(".mx_EventTile_e2eIcon"); + if ((await e2eIcon.count()) > 0) { + // uh-oh, there is an e2e icon. Let's find out what it's about so that we can throw a helpful error. + await e2eIcon.focus(); + const tooltip = await app.getTooltipForElement(e2eIcon); + throw new Error(`Found an unexpected e2eIcon with tooltip '${await tooltip.textContent()}'`); + } +} From 4607325a9b1bd1c63491bb7878c06c112f961f9a Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 4 Dec 2024 21:34:39 +0000 Subject: [PATCH 2/2] 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 https://github.com/element-hq/element-web/issues/28061 --- playwright/e2e/crypto/event-shields.spec.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/playwright/e2e/crypto/event-shields.spec.ts b/playwright/e2e/crypto/event-shields.spec.ts index 84b908bf6d1..0beb8e36500 100644 --- a/playwright/e2e/crypto/event-shields.spec.ts +++ b/playwright/e2e/crypto/event-shields.spec.ts @@ -280,6 +280,15 @@ test.describe("Cryptography", function () { bot: bob, homeserver, }) => { + // Workaround for https://github.com/element-hq/element-web/issues/28640: + // make sure that Alice has seen Bob's identity before she goes offline. We do this by opening + // his user info. + await app.toggleRoomInfoPanel(); + const rightPanel = page.locator(".mx_RightPanel"); + await rightPanel.getByRole("menuitem", { name: "People" }).click(); + await rightPanel.getByRole("button", { name: bob.credentials!.userId }).click(); + await expect(rightPanel.locator(".mx_UserInfo_devices")).toContainText("1 session"); + // Our app is blocked from syncing while Bob sends his messages. await app.client.network.goOffline();