Saltar al contenido
Skillpedia
Pruebas14 mil · #11275

login-flows

Qué hace

Esta skill ofrece patrones para automatizar inicios de sesión en sitios web en pruebas de extremo a extremo con Playwright. Está pensada para desarrolladores que prueban aplicaciones web y quieren evitar iniciar sesión antes de cada prueba.

Cuándo usarla

  • ✓Cuando escribes pruebas automatizadas para un sitio que requiere inicio de sesión.
  • ✓Cuando tus pruebas usan Google u otro proveedor de inicio de sesión único.
  • ✓Cuando quieres guardar el estado de inicio de sesión para que las pruebas se ejecuten más rápido.

Link de la skill

https://github.com/andrewyng/context-hub/blob/main/content/playwright-community/skills/login-flows/SKILL.md

Cópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.

Cómo usar

La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.

Mensaje listo para pegar

Usa esta skill para ayudarme: https://github.com/andrewyng/context-hub/blob/main/content/playwright-community/skills/login-flows/SKILL.md Lee el archivo SKILL.md de ese link y sigue sus instrucciones en mi tarea.
¿Quieres que tu IA encuentre skills como esta por sí sola?Instala el MCP gratis de Skillpedia: una línea, y busca entre 15.000+ skills antes de cada tarea.Instalar en 1 minuto →

Ejemplo de qué pedirle a la IA

“Quiero una función auxiliar de prueba en Playwright que inicie sesión en mi app con usuario y contraseña.”

5 skills nuevas por semana. 1 minuto de lectura.

Cómo funciona

La skill muestra ejemplos de código cortos para cada tipo de inicio de sesión, incluido guardar el estado de inicio de sesión del navegador una vez y reutilizarlo. El agente adapta estos ejemplos a tu app.

Contenido técnico (SKILL.md original)

Texto original del autor, en inglés, directo de 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 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
Preguntas frecuentes

¿Funciona solo con Playwright?

Los ejemplos están escritos para Playwright, una herramienta de pruebas en navegador.

¿En qué ayuda guardar el estado de inicio de sesión?

Inicia sesión una vez en un paso de preparación, de modo que las pruebas pueden reutilizar el estado guardado.

¿Cubre el inicio de sesión con Google?

Sí. Incluye un ejemplo de inicio de sesión con OAuth o SSO que redirige a un proveedor externo.

Detalles

Descripción original del autor

Common login automation patterns for web apps using Playwright

repo: andrewyng/context-hub

Popularidad

Estrellas en GitHub
14 mil
Posición en el ranking
#11275
Licencia
MIT
Actualizada
31/5/2026

¿Te sirve esta skill?

0

Entra para votar.

Comentarios

  • …

Más skills de este repositorio

Skills parecidas