auth.setup.ts 989 B

123456789101112131415161718192021222324
  1. import { test as setup, expect } from '@playwright/test';
  2. const authFile = 'playwright/.auth/user.json';
  3. setup('authenticate', async({ page }) => {
  4. // Perform authentication steps. Replace these actions with your own.
  5. await page.goto('/admin');
  6. await page.waitForURL('/login');
  7. await page.getByLabel('Username or email address').fill('admin');
  8. await page.getByLabel('Password').fill('adminadmin');
  9. await page.getByRole('button', { name: 'Sign in' }).click();
  10. // Wait until the page receives the cookies.
  11. //
  12. // Sometimes login flow sets cookies in the process of several redirects.
  13. // Wait for the final URL to ensure that the cookies are actually set.
  14. await page.waitForURL('/admin');
  15. // Alternatively, you can wait until the page reaches a state where all cookies are set.
  16. await expect(page.getByRole('button', { name: 'View profile and more' })).toBeVisible();
  17. // End of authentication steps.
  18. await page.context().storageState({ path: authFile });
  19. });