Skip to content

Commit 9207457

Browse files
Wait for token request to finish after login in e2e-test
Our e2e-tests are currently flaky while logging in due to the following error: Error "apiRequestContext.fetch: Target page, context or browser has been closed" while running route callback. This then leads to errors in all other tests as the token file is not created: ENOENT: no such file or directory, open '[...]/e2e/storage/token.json' To (hopefully) fix this we wait for all route-handlers to finish their processing before closing the browser. RISDEV-0000
1 parent 9838921 commit 9207457

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

frontend/e2e/globalSetup/login-and-create-sample-data.setup.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ setup("login", async ({ page }) => {
1616
await page.getByRole("button", { name: "Sign In" }).click()
1717

1818
await page.context().storageState({ path: `e2e/storage/state.json` })
19+
20+
await page.waitForURL("/")
21+
await page.unrouteAll({ behavior: "wait" })
1922
})
2023

2124
setup("create sample data", async ({ authenticatedRequest: request }) => {

frontend/e2e/utils/test-with-auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const test = base.extend<{
4141
async ({ page }, use) => {
4242
await page.route(/token$/, async (route) => {
4343
const response = await page.request.fetch(route.request())
44-
if (response.ok()) saveToken(await response.json())
44+
if (response.ok()) await saveToken(await response.json())
4545
await route.fulfill({ response })
4646
})
4747

0 commit comments

Comments
 (0)