Playwright mcp testing

From Hectr203/V2-VIDEOS-IA · View interactive version

Playwright mcp testing is an AI agent skill from the GitHub repository Hectr203/V2-VIDEOS-IA. QA y testing con Playwright MCP para proyectos nuevos. Usar para escribir y ejecutar pruebas E2E, de integracion y unitarias usando Playwright y el protocolo MCP. Incluye configuracion, reporteria y CI.

How to use this skill

Skill file

Integración en Agencia Principal

Aplicar el contrato de selección y coordinación. Activar esta habilidad solo si su resultado corresponde al alcance autorizado; los ejemplos de stack y herramientas no sustituyen el manifiesto. Recursos relativos se resuelven desde esta fuente. No ampliar permisos, invocar procesos recursivos ni declarar controles no ejecutados.

Playwright MCP Testing

Proposito

Integrar Playwright como framework de testing E2E y de integracion en proyectos nuevos, usando el ecosistema MCP para orquestacion automatica de navegadores. Esta skill garantiza que el proyecto tenga pruebas reales desde el dia uno, sin configuracion manual repetitiva.

Prerequisitos

Configuracion de Playwright MCP

1. Instalar dependencias

npm install -D @playwright/test
npx playwright install --with-deps chromium

2. Configurar playwright.config.ts

import { defineConfig } from '@playwright/test';

export default defineConfig({
  testDir: './tests',
  fullyParallel: true,
  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 2 : 0,
  workers: process.env.CI ? 1 : undefined,
  reporter: [['html'], ['list']],
  use: {
    baseURL: process.env.BASE_URL || 'https://localhost:5173',
    trace: 'on-first-retry',
    screenshot: 'only-on-failure',
  },
  projects: [
    { name: 'chromium', use: { browserName: 'chromium' } },
  ],
});

3. Integracion MCP para agentes

Los agentes usan Playwright MCP server para ejecutar pruebas en navegadores reales. El MCP server expone herramientas para:

Flujo de trabajo

Fase 1 - Analisis

  1. Identificar flujos criticos del modulo.
  2. Definir que probar: unitario, integracion o E2E.
  3. Revisar contratos API, DTOs y tipos.

Fase 2 - Pruebas unitarias

// tests/unitarios/nombre-modulo.test.ts
import { describe, it, expect } from '@playwright/test';

describe('NombreModulo', () => {
  it('debe procesar entrada valida correctamente', () => {
    const resultado = funcionAProbar(entradaValida);
    expect(resultado).toEqual(esperado);
  });

  it('debe rechazar entrada invalida con error', () => {
    expect(() => funcionAProbar(entradaInvalida)).toThrow('mensaje de error');
  });
});

Fase 3 - Pruebas de integracion

// tests/integracion/api-nombre-modulo.test.ts
import { test, expect } from '@playwright/test';

test('POST /api/modulo debe crear recurso', async ({ request }) => {
  const respuesta = await request.post('/api/modulo', {
    data: { /* datos */ }
  });
  expect(respuesta.ok()).toBeTruthy();
  expect(await respuesta.json()).toMatchObject({
    ok: true
  });
});

Fase 4 - Pruebas E2E con Playwright MCP

// tests/e2e/flujo-critico.test.ts
import { test, expect } from '@playwright/test';

test('flujo completo de usuario', async ({ page }) => {
  await page.goto('/');
  await page.click('text=Iniciar Sesion');
  await page.fill('[name="email"]', 'test@example.com');
  await page.fill('[name="password"]', 'password123');
  await page.click('button[type="submit"]');
  await expect(page.locator('text=Dashboard')).toBeVisible();
});

Fase 5 - Reporteria y CI

# .github/workflows/test.yml
name: Tests
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 22
      - run: npm ci
      - run: npx playwright install --with-deps chromium
      - run: npm test
      - uses: actions/upload-artifact@v4
        if: failure()
        with:
          name: playwright-report
          path: playwright-report/

Reglas

  1. No mezclar niveles de prueba en un mismo archivo.
  2. Cada prueba debe verificar UN concepto.
  3. Usar describe/it para estructura BDD.
  4. Pruebas E2E solo para flujos criticos de usuario.
  5. Mockear solo fronteras del sistema (API externa, base de datos).
  6. No usar snapshot tests como unica validacion.
  7. Etiquetar pruebas lentas con test.slow().
  8. Los nombres de prueba deben describir comportamiento en espanol.

Salidas

Referencias

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.