From 736b083a79008b2f861947f09298229bec71d1bd Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Fri, 21 Jun 2024 17:58:38 +0100 Subject: [PATCH] Deflake verification playwright tests (#12669) Turns out the sleep that got removed in https://github.com/matrix-org/matrix-react-sdk/pull/12667 was useful. --- playwright/e2e/crypto/utils.ts | 7 +++++++ playwright/e2e/crypto/verification.spec.ts | 14 ++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/playwright/e2e/crypto/utils.ts b/playwright/e2e/crypto/utils.ts index 5b0bf29b97..b5109490a9 100644 --- a/playwright/e2e/crypto/utils.ts +++ b/playwright/e2e/crypto/utils.ts @@ -113,6 +113,13 @@ export async function checkDeviceIsConnectedKeyBackup( expectedBackupVersion: string, checkBackupKeyInCache: boolean, ): Promise { + // Sanity check the given backup version: if it's null, something went wrong earlier in the test. + if (!expectedBackupVersion) { + throw new Error( + `Invalid backup version passed to \`checkDeviceIsConnectedKeyBackup\`: ${expectedBackupVersion}`, + ); + } + await page.getByRole("button", { name: "User menu" }).click(); await page.locator(".mx_UserMenu_contextMenu").getByRole("menuitem", { name: "Security & Privacy" }).click(); await expect(page.locator(".mx_Dialog").getByRole("button", { name: "Restore from Backup" })).toBeVisible(); diff --git a/playwright/e2e/crypto/verification.spec.ts b/playwright/e2e/crypto/verification.spec.ts index 126195a675..1b11854652 100644 --- a/playwright/e2e/crypto/verification.spec.ts +++ b/playwright/e2e/crypto/verification.spec.ts @@ -50,11 +50,17 @@ test.describe("Device verification", () => { bootstrapSecretStorage: true, }); aliceBotClient.setCredentials(credentials); - const mxClientHandle = await aliceBotClient.prepareClient(); - expectedBackupVersion = await mxClientHandle.evaluate(async (mxClient) => { - return await mxClient.getCrypto()!.getActiveSessionBackupVersion(); - }); + // Backup is prepared in the background. Poll until it is ready. + const botClientHandle = await aliceBotClient.prepareClient(); + await expect + .poll(async () => { + expectedBackupVersion = await botClientHandle.evaluate((cli) => + cli.getCrypto()!.getActiveSessionBackupVersion(), + ); + return expectedBackupVersion; + }) + .not.toBe(null); }); // Click the "Verify with another device" button, and have the bot client auto-accept it.