16. Global Authentication & Session Reuse

Global Auth Setup (auth.setup.js)

import { test as setup } from "@playwright/test";

setup("authenticate user", async ({ page }) => {
await page.goto("/login");
await page.getByLabel("Email").fill("tester@targetqa.com");
await page.getByLabel("Password").fill("Password123!");
await page.getByRole("button", { name: "Sign in" }).click();
await page.waitForURL("**/dashboard");

// Save session state to disk:
await page.context().storageState({ path: "playwright/.auth/user.json" });
});

Task

  • Implement getStorageConfig:
  • 1. Accept authPath string.
  • 2. Return { storageState: authPath }.
πŸ’‘Common doubts
Did you like the problem?
Lesson 16 of 18
JavaScript
Loading code editor…
Next