Skip to content

Commit

Permalink
Wait for token request to finish after login in e2e-test
Browse files Browse the repository at this point in the history
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
  • Loading branch information
malte-laukoetter committed Feb 14, 2025
1 parent 9838921 commit 9207457
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ setup("login", async ({ page }) => {
await page.getByRole("button", { name: "Sign In" }).click()

await page.context().storageState({ path: `e2e/storage/state.json` })

await page.waitForURL("/")
await page.unrouteAll({ behavior: "wait" })
})

setup("create sample data", async ({ authenticatedRequest: request }) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/e2e/utils/test-with-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const test = base.extend<{
async ({ page }, use) => {
await page.route(/token$/, async (route) => {
const response = await page.request.fetch(route.request())
if (response.ok()) saveToken(await response.json())
if (response.ok()) await saveToken(await response.json())
await route.fulfill({ response })
})

Expand Down

0 comments on commit 9207457

Please sign in to comment.