Skip to content
Skillv1.0.0

login-flows

Common login automation patterns for web apps using Playwright

by andrewyng(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from andrewyng/context-hub (content/playwright-community/skills/login-flows/SKILL.md). Install upstream with npx skills add andrewyng/context-hub --skill login-flows. Copyright stays with the author.

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

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/andrewyng-context-hub-login-flows/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

andrewyng-context-hub-login-flows.ocm.jsonjson
{
  "ocm": "1",
  "id": "andrewyng-context-hub-login-flows",
  "kind": "skill",
  "name": "login-flows",
  "description": "Common login automation patterns for web apps using Playwright",
  "publisher": "andrewyng",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "general"
    ],
    "tags": [
      "skill-md",
      "browser",
      "automation",
      "playwright",
      "login",
      "testing",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Common login automation patterns for web apps using Playwright"
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/andrewyng/context-hub",
      "path": "content/playwright-community/skills/login-flows/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/andrewyng/context-hub/blob/HEAD/content/playwright-community/skills/login-flows/SKILL.md",
      "key": "andrewyng/context-hub/content/playwright-community/skills/login-flows/SKILL.md"
    }
  },
  "instructions": "# Login Flow Patterns for Playwright\n\nReusable patterns for automating login flows in end-to-end tests.\n\n## Basic Username/Password Login\n\n```typescript\nimport { Page } from '@playwright/test';\n\nasync function login(page: Page, username: string, password: string) {\n  await page.goto('/login');\n  await page.fill('[name=\"username\"]', username);\n  await page.fill('[name=\"password\"]', password);\n  await page.click('button[type=\"submit\"]');\n  await page.waitForURL('/dashboard');\n}\n```\n\n## OAuth / SSO Login\n\nFor OAuth flows that redirect to an external provider:\n\n```typescript\nasync function loginWi",
  "cost": {
    "context_tokens": 660
  }
}

Fetch it by URL: GET /api/v1/registry/andrewyng-context-hub-login-flows/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.