From e381055a8c5cd13afa930c87ab95af5447d6169d Mon Sep 17 00:00:00 2001 From: Brad Peters Date: Thu, 27 Jul 2023 12:34:45 -0700 Subject: [PATCH] fix(test): Wait for network idle --- packages/vue3/test/e2e/hcaptcha.test.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/vue3/test/e2e/hcaptcha.test.js b/packages/vue3/test/e2e/hcaptcha.test.js index 19fb4d1..e8cd58c 100644 --- a/packages/vue3/test/e2e/hcaptcha.test.js +++ b/packages/vue3/test/e2e/hcaptcha.test.js @@ -49,7 +49,8 @@ async function waitForFrame(ownerFrame, name, hcaptchaId) { { state: "attached" } ); const frame = await elem.contentFrame(); - await frame.waitForLoadState(); + await frame.waitForLoadState("networkidle"); + return { elem, frame }; } @@ -72,10 +73,14 @@ describe("hCaptcha vue3", () => { beforeEach(async () => { page = await browser.newPage({ bypassCSP: true }); + setupPage(page); + await page.setViewportSize({ width: 1280, height: 720 }); await page.route(/https:\/\/hcaptcha\.local/, route => route.fulfill({ body: HTML })); await page.goto("https://hcaptcha.local"); + + await page.waitForLoadState("networkidle"); }); afterEach(async () => { @@ -85,18 +90,22 @@ describe("hCaptcha vue3", () => { it("should render anchor", async () => { const { frame } = await waitForFrame(page, "checkbox"); const anchor = await frame.$("#anchor"); + expect(await anchor.screenshot()).toMatchImageSnapshot({ failureThreshold: 0.01 }); }); it("should get token", async () => { const onVerifyMock = jest.fn(); await page.exposeBinding("onVerify", onVerifyMock); - const getRequestPromise = page.waitForRequest("**/getcaptcha?*"); + const { frame } = await waitForFrame(page, "checkbox"); const anchor = await frame.$("#anchor"); + await anchor.click(); - await getRequestPromise; + await page.waitForRequest("**/getcaptcha?*"); + await frame.waitForSelector(".check"); + expect(onVerifyMock).toHaveBeenCalledTimes(1); expect(onVerifyMock).toHaveBeenCalledWith(expect.anything(), { token: "10000000-aaaa-bbbb-cccc-000000000001", eKey: "" }); expect(await anchor.screenshot()).toMatchImageSnapshot({ failureThreshold: 0.01 });