본문으로 건너뛰기
cccskills
무료GitHub에 공개

playwright-auth-state

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

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

연동 도구Playwright
설치 방법 보기

포함된 파일(1)

  • SKILL.md5.0 KB

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.

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Conducts rigorous authoring and review of Playwright E2E tests. Enforces accessibility-first locators, web-first assertions, strict isolation, and DAMP architecture. Use when generating, refactoring, or reviewing any Playwright test code.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

hzijad/playwright-agent-skills92026년 7월 16일 업데이트

Diagnostic Playwright workflows for flaky or failing tests, including trace analysis, UI mode, and state isolation.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

hzijad/playwright-agent-skills92026년 7월 16일 업데이트

Playwright workflows for deterministic third-party responses using page.route().

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

hzijad/playwright-agent-skills92026년 7월 16일 업데이트

hzijad의 스킬 모두 보기

이 스킬의 문제 신고