agentleFS
hzijadhzijad/playwright-agent-skills/skills/playwright-auth-state/SKILL.md

playwright-auth-state

Skill9 starsChanged 4 months agoMITView on GitHub

Playwright workflows for authenticated browser state reuse through storageState and setup projects.

The file

Show its rules and text

We split this skill into the rules it gives an agent

15 rules. About 0 are common, 14 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈14

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when tests need to start in a known logged-in session or with a role-specific browser state instead of repeating the login …

    line 10
  2. Distinctive:

    Do not use this skill when the login form itself is the feature under test, or when the app is fully local and does not need shared browser …

    line 12
  3. Distinctive:

    When a test requires an already authenticated user.

    line 16
  4. Distinctive:

    When a suite benefits from reusing browser state across many tests.

    line 17
  5. Distinctive:

    When you need separate roles or permissions without redoing the UI login.

    line 18
  6. Distinctive:

    When the login flow is the feature under test.

    line 22
  7. Distinctive:

    When the app behavior is fully local and does not depend on stored session state.

    line 23
  8. Very specific:

    When you are diagnosing a flake that should be fixed first in playwright-debugging.

    line 24
  9. Distinctive:

    Create the authenticated state once in a setup project, then load it in the tests that need it.

    line 28
  10. Distinctive:

    If only some tests need the logged-in session, scope the state to a specific project rather than making it global.

    line 68
  11. Distinctive:

    Treat the generated storage state as a build artifact, not source code.

    line 70
  12. Distinctive:

    When a suite needs more than one authenticated identity — an admin and a standard user, for example — create one setup test and one storage …

    line 74
  13. Distinctive:

    Keep the setup file and the auth state file in a predictable location:

    line 132
  14. Distinctive:

    Keep the setup test focused on creating state, not on exercising the full product flow.

    line 138
  15. Distinctive:

    Verify the state file was created and loaded correctly.

    line 142

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Playwright Auth State

Overview

Use this skill when tests need to start in a known logged-in session or with a role-specific browser state instead of repeating the login UI in every spec. It keeps the browser state deterministic without making authentication the focus of the test.

Do not use this skill when the login form itself is the feature under test, or when the app is fully local and does not need shared browser state.

When to Use

  • When a test requires an already authenticated user.
  • When a suite benefits from reusing browser state across many tests.
  • When you need separate roles or permissions without redoing the UI login.

When Not to Use

  • When the login flow is the feature under test.
  • When the app behavior is fully local and does not depend on stored session state.
  • When you are diagnosing a flake that should be fixed first in playwright-debugging.

Authenticated State

Create the authenticated state once in a setup project, then load it in the tests that need it.

// tests/auth.setup.ts
import { test as setup, expect } from '@playwright/test';

setup('authenticate', async ({ page }) => {
  await page.goto('/login');
  await page.getByLabel('Email').fill('user@example.com');
  await page.getByLabel('Password').fill('password123');
  await page.getByRole('button', { name: 'Sign in' }).click();

  await expect(page.getByRole('button', { name: 'Sign out' })).toBeVisible();
  await page.context().storageState({ path: 'playwright/.auth/user.json' });
});

Apply the saved state in configuration:

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
  projects: [
    {
      name: 'setup',
      testMatch: /.*\.setup\.ts/,
    },
    {
      name: 'chromium',
      dependencies: ['setup'],
      use: {
        storageState: 'playwright/.auth/user.json',
      },
    },
  ],
});

If only some tests need the logged-in session, scope the state to a specific project rather than making it global. For multiple roles, keep one state file per role and give each project a clear name.

Treat the generated storage state as a build artifact, not source code. Keep it out of version control unless your project has a specific reason to commit it.

Multiple Roles

When a suite needs more than one authenticated identity — an admin and a standard user, for example — create one setup test and one storage state file per role, and give each project a name that makes the role obvious at a glance.

// tests/auth.setup.ts
import { test as setup, expect } from '@playwright/test';

setup('authenticate as admin', async ({ page }) => {
  await page.goto('/login');
  await page.getByLabel('Email').fill('admin@example.com');
  await page.getByLabel('Password').fill('adminpass123');
  await page.getByRole('button', { name: 'Sign in' }).click();

  await expect(page.getByRole('heading', { name: 'Admin Dashboard' })).toBeVisible();
  await page.context().storageState({ path: 'playwright/.auth/admin.json' });
});

setup('authenticate as user', async ({ page }) => {
  await page.goto('/login');
  await page.getByLabel('Email').fill('user@example.com');
  await page.getByLabel('Password').fill('password123');
  await page.getByRole('button', { name: 'Sign in' }).click();

  await expect(page.getByRole('button', { name: 'Sign out' })).toBeVisible();
  await page.context().storageState({ path: 'playwright/.auth/user.json' });
});
// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
  projects: [
    { name: 'setup', testMatch: /.*\.setup\.ts/ },
    {
      name: 'chromium-admin',
      dependencies: ['setup'],
      testMatch: /.*\.admin\.spec\.ts/,
      use: { storageState: 'playwright/.auth/admin.json' },
    },
    {
      name: 'chromium-user',
      dependencies: ['setup'],
      testMatch: /.*\.user\.spec\.ts/,
      use: { storageState: 'playwright/.auth/user.json' },
    },
  ],
});

Route each spec to the project whose role it needs through a file naming convention such as *.admin.spec.ts and *.user.spec.ts. Keep the matchers explicit so a project never becomes a catch-all for unrelated specs.

Recommended Project Shape

Keep the setup file and the auth state file in a predictable location:

  • tests/auth.setup.ts
  • playwright/.auth/user.json
  • playwright.config.ts

Keep the setup test focused on creating state, not on exercising the full product flow. The setup project should end as soon as the authenticated signal is visible and the storage state has been written.

Verification

Verify the state file was created and loaded correctly.

Typical checks:

npx playwright test --project=setup
npx playwright test tests/dashboard.spec.ts

For debugging, use trace viewer or UI mode to confirm the login state is present in the resulting session.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.