login-flows

Login Flow Patterns for Playwright

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "login-flows" with this command: npx skills add andrewyng/context-hub/andrewyng-context-hub-login-flows

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 storageState to 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 arbitrary waitForTimeout() after login

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

get-api-docs

No summary provided by upstream source.

Repository SourceNeeds Review
General

skill

No summary provided by upstream source.

Repository SourceNeeds Review
General

neo

Browse websites, read web pages, interact with web apps, call website APIs, and automate web tasks. Use Neo when: user asks to check a website, read a web page, post on social media (Twitter/X), interact with any web app, look up information on a specific site, scrape data from websites, automate browser tasks, or when you need to call any website's API. Keywords: website, web page, browse, URL, http, API, twitter, tweet, post, scrape, web app, open site, check site, read page, social media, online service.

Archived SourceRecently Updated
General

image-gen

Generate AI images from text prompts. Triggers on: "生成图片", "画一张", "AI图", "generate image", "配图", "create picture", "draw", "visualize", "generate an image".

Archived SourceRecently Updated