login-flows
What it does
This skill gives patterns for automating website logins in end-to-end tests using Playwright. It is for developers who test web apps and want to avoid logging in before every test.
When to use it
- ✓When you write automated tests for a site that needs a login.
- ✓When your tests use Google or another single sign-on provider.
- ✓When you want to save login state so tests run faster.
Skill link
https://github.com/andrewyng/context-hub/blob/main/content/playwright-community/skills/login-flows/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“I want a Playwright test helper that logs into my app with a username and password.”
5 new skills a week. 1 minute to read.
How it works
The skill shows short code examples for each login type, including saving the browser's login state once and reusing it. The agent adapts these examples to your app.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Login Flow Patterns for Playwright
Reusable patterns for automating login flows in end-to-end tests.
Basic Username/Password Login
import { Page } from '@playwright/test';
async function login(page: Page, username: string, password: string) {
await page.goto('/login');
await page.fill('[name="username"]', username);
await page.fill('[name="password"]', password);
await page.click('button[type="submit"]');
await page.waitForURL('/dashboard');
}
OAuth / SSO Login
For OAuth flows that redirect to an external provider:
async function loginWithOAuth(page: Page) {
await page.goto('/login');
await page.click('text=Sign in with Google');
// Handle the OAuth popup or redirect
await page.fill('input[type="email"]', process.env.TEST_EMAIL!);
await page.click('text=Next');
await page.fill('input[type="password"]', process.env.TEST_PASSWORD!);
await page.click('text=Next');
// Wait for redirect back to app
await page.waitForURL('**/dashboard');
}
Persisting Auth State (storageState)
Avoid logging in before every test by saving and reusing browser state:
// global-setup.ts — runs once before all tests
import { chromium } from '@playwright/test';
async function globalSetup() {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('/login');
await page.fill('[name="username"]', 'testuser');
await page.fill('[name="password"]', 'testpass');
await page.click('button[type="submit"]');
await page.waitForURL('/dashboard');
// Save signed-in state
await page.context().storageState({ path: './auth.json' });
await browser.close();
}
export default globalSetup;
Then in playwright.config.ts:
export default defineConfig({
globalSetup: './global-setup.ts',
use: {
storageState: './auth.json',
},
});
MFA / 2FA Handling
For test environments with TOTP-based 2FA:
import { authenticator } from 'otplib';
async function loginWithMFA(page: Page, secret: string) {
await login(page, 'user', 'pass');
// Generate TOTP code
const code = authenticator.generate(secret);
await page.fill('[name="totp"]', code);
await page.click('button[type="submit"]');
await page.waitForURL('/dashboard');
}
Tips
- Always use
storageStateto avoid repeated logins — it's the single biggest speedup for E2E suites - Use environment variables for credentials, never hardcode them
- For CI, consider a dedicated test user with stable credentials
- Use
page.waitForURL()instead of arbitrarywaitForTimeout()after login
FAQ
Does it work only with Playwright?
The examples are written for Playwright, a browser testing tool.
How does saved login state help?
It logs in once in a setup step, so tests can reuse the saved state.
Does it cover login with Google?
Yes. It includes an example for OAuth or SSO login that redirects to an outside provider.
Details
Original description by the author
Common login automation patterns for web apps using Playwright
repo: andrewyng/context-hub
Popularity
- GitHub stars
- 14k
- Ranking position
- #11275
- License
- MIT
- Updated
- 5/31/2026
Comments
- …
More skills from this repository
get-api-docs
14kHelps your agent fetch current documentation for third-party APIs and libraries before writing code, instead of relying on old memory.
bloc-cubit
14kTeaches your agent how to manage app state in Flutter with Bloc or Cubit, including when to pick each one and safe defaults for testing.
riverpod
14kTeaches your agent how to manage Flutter app state with Riverpod, covering providers, async data, and testing, with sensible defaults for each case.
document-extraction
14kHelps your agent read PDFs, images, and spreadsheets, turn them into clean text, and pull out fields like invoice totals using LandingAI's ADE service.
Similar skills
test-driven-development
311kTeaches your agent to write a failing test first, watch it fail, then write the smallest code that passes, before building any feature or fix.
verification-before-completion
311kTeaches your agent to run real checks and read their output before claiming that a task, fix, or build is complete or passing.
migrate-to-shoehorn
310kReplaces risky type casts in your test files with the shoehorn library, so tests can use partial data and still pass type checks.