From a81ce3f13d7ccd784bdefef2d6344a4d3473bc51 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Wed, 22 Feb 2023 14:02:27 -0800 Subject: [PATCH] docs(auth): wait for the response with cookies (#21114) Fixes #21096 --- docs/src/auth.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/docs/src/auth.md b/docs/src/auth.md index 4682381f51..744f8bd636 100644 --- a/docs/src/auth.md +++ b/docs/src/auth.md @@ -55,6 +55,14 @@ setup('authenticate', async ({ page }) => { await page.getByLabel('Username or email address').fill('username'); await page.getByLabel('Password').fill('password'); await page.getByRole('button', { name: 'Sign in' }).click(); + // Wait until the page receives the cookies. + // + // Sometimes login flow sets cookies in the process of several redirects. + // Wait for the final URL to ensure that the cookies are actually set. + await page.waitForURL('https://github.com/'); + // Alternatively, you can wait until the page reaches a state where all cookies are set. + await expect(page.getByRole('button', { name: 'View profile and more' })).toBeVisible(); + // End of authentication steps. await page.context().storageState({ path: authFile }); @@ -161,6 +169,14 @@ export const test = baseTest.extend<{}, { workerStorageState: string }>({ await page.getByLabel('Username or email address').fill(account.username); await page.getByLabel('Password').fill(account.password); await page.getByRole('button', { name: 'Sign in' }).click(); + // Wait until the page receives the cookies. + // + // Sometimes login flow sets cookies in the process of several redirects. + // Wait for the final URL to ensure that the cookies are actually set. + await page.waitForURL('https://github.com/'); + // Alternatively, you can wait until the page reaches a state where all cookies are set. + await expect(page.getByRole('button', { name: 'View profile and more' })).toBeVisible(); + // End of authentication steps. await page.context().storageState({ path: fileName }); @@ -393,6 +409,14 @@ setup('authenticate as admin', async ({ page }) => { await page.getByLabel('Username or email address').fill('admin'); await page.getByLabel('Password').fill('password'); await page.getByRole('button', { name: 'Sign in' }).click(); + // Wait until the page receives the cookies. + // + // Sometimes login flow sets cookies in the process of several redirects. + // Wait for the final URL to ensure that the cookies are actually set. + await page.waitForURL('https://github.com/'); + // Alternatively, you can wait until the page reaches a state where all cookies are set. + await expect(page.getByRole('button', { name: 'View profile and more' })).toBeVisible(); + // End of authentication steps. await page.context().storageState({ path: adminFile }); @@ -406,6 +430,14 @@ setup('authenticate as user', async ({ page }) => { await page.getByLabel('Username or email address').fill('user'); await page.getByLabel('Password').fill('password'); await page.getByRole('button', { name: 'Sign in' }).click(); + // Wait until the page receives the cookies. + // + // Sometimes login flow sets cookies in the process of several redirects. + // Wait for the final URL to ensure that the cookies are actually set. + await page.waitForURL('https://github.com/'); + // Alternatively, you can wait until the page reaches a state where all cookies are set. + await expect(page.getByRole('button', { name: 'View profile and more' })).toBeVisible(); + // End of authentication steps. await page.context().storageState({ path: userFile });