Saltar a contenido

QA Engineer - Guía de Entorno

Esta guía detalla las herramientas necesarias para que Claude Code pueda ayudarte eficazmente en testing automatizado y QA.

Resumen de Capacidades

Capacidad Herramientas Requeridas
E2E Testing Playwright, Cypress, Selenium
Unit Testing Jest, Vitest, pytest, xUnit
API Testing Postman, Newman, HTTPie
Performance k6, JMeter, Lighthouse
Visual Regression Percy, Chromatic, BackstopJS
Accessibility axe-core, Pa11y

End-to-End Testing

Playwright (Recomendado)

# Instalar
npm init playwright@latest
# o
pnpm create playwright

# Estructura creada:
# tests/
# playwright.config.ts

# Ejecutar tests
npx playwright test

# Con UI mode
npx playwright test --ui

# Debug mode
npx playwright test --debug

# Generar tests
npx playwright codegen localhost:3000

# Ver reporte
npx playwright show-report

# Screenshots/Videos automáticos en CI
npx playwright test --reporter=html

playwright.config.ts básico:

import { defineConfig, devices } from '@playwright/test'

export default defineConfig({
  testDir: './tests',
  fullyParallel: true,
  reporter: 'html',
  use: {
    baseURL: 'http://localhost:3000',
    trace: 'on-first-retry',
    screenshot: 'only-on-failure',
    video: 'on-first-retry',
  },
  projects: [
    { name: 'chromium', use: { ...devices['Desktop Chrome'] } },
    { name: 'firefox', use: { ...devices['Desktop Firefox'] } },
    { name: 'webkit', use: { ...devices['Desktop Safari'] } },
    { name: 'Mobile Chrome', use: { ...devices['Pixel 5'] } },
    { name: 'Mobile Safari', use: { ...devices['iPhone 12'] } },
  ],
  webServer: {
    command: 'npm run dev',
    url: 'http://localhost:3000',
    reuseExistingServer: !process.env.CI,
  },
})

Cypress

# Instalar
npm install -D cypress

# Abrir GUI
npx cypress open

# Ejecutar headless
npx cypress run

# Ejecutar spec específico
npx cypress run --spec "cypress/e2e/login.cy.ts"

# Con grabación en Cypress Cloud
npx cypress run --record --key <key>

Selenium WebDriver

# Instalar con Node.js
npm install selenium-webdriver

# Chromedriver
npm install chromedriver

# O con Python
pip install selenium webdriver-manager

API Testing

Postman + Newman (CLI)

# Instalar Newman
npm install -g newman

# Ejecutar colección
newman run collection.json

# Con environment
newman run collection.json -e environment.json

# Con reporter HTML
npm install -g newman-reporter-html
newman run collection.json -r html

# CI/CD integration
newman run collection.json --reporters cli,junit --reporter-junit-export results.xml

HTTPie

# Instalar
pip install httpie

# Uso
http GET https://api.example.com/users
http POST https://api.example.com/users name=John email=john@example.com
http --auth user:pass GET https://api.example.com/protected

REST Client (VS Code)

code --install-extension humao.rest-client

# Crear archivo .http
# GET https://api.example.com/users
#
# ###
#
# POST https://api.example.com/users
# Content-Type: application/json
#
# {
#   "name": "John"
# }

Performance Testing

k6 (Recomendado)

# Instalar
# Windows
winget install k6.k6

# macOS
brew install k6

# Linux
sudo apt install k6

# Ejecutar
k6 run script.js

# Con cloud
k6 cloud script.js

Ejemplo script.js:

import http from 'k6/http'
import { check, sleep } from 'k6'

export const options = {
  vus: 10,          // Virtual users
  duration: '30s',  // Duración
  thresholds: {
    http_req_duration: ['p(95)<500'], // 95% < 500ms
  },
}

export default function () {
  const res = http.get('https://api.example.com/users')
  check(res, {
    'status is 200': (r) => r.status === 200,
    'response time < 500ms': (r) => r.timings.duration < 500,
  })
  sleep(1)
}

Lighthouse CI

# Instalar
npm install -g @lhci/cli

# Ejecutar
lhci autorun

# Configurar lighthouserc.js
module.exports = {
  ci: {
    collect: {
      url: ['http://localhost:3000/'],
      numberOfRuns: 3,
    },
    assert: {
      preset: 'lighthouse:recommended',
    },
    upload: {
      target: 'temporary-public-storage',
    },
  },
}

Accessibility Testing

axe-core + Playwright

npm install -D @axe-core/playwright
import { test, expect } from '@playwright/test'
import AxeBuilder from '@axe-core/playwright'

test('should not have accessibility violations', async ({ page }) => {
  await page.goto('/')
  const accessibilityScanResults = await new AxeBuilder({ page }).analyze()
  expect(accessibilityScanResults.violations).toEqual([])
})

Pa11y

# Instalar
npm install -g pa11y pa11y-ci

# Ejecutar
pa11y https://example.com

# CI mode
pa11y-ci --config .pa11yci.json

Visual Regression Testing

Playwright Visual Comparisons

import { test, expect } from '@playwright/test'

test('visual regression', async ({ page }) => {
  await page.goto('/')
  await expect(page).toHaveScreenshot('homepage.png')
})

// Actualizar snapshots
// npx playwright test --update-snapshots

BackstopJS

npm install -g backstopjs

backstop init
backstop test
backstop approve  # Aprobar cambios
backstop reference  # Generar referencias

Test Frameworks por Lenguaje

JavaScript/TypeScript

# Vitest (recomendado)
pnpm add -D vitest
pnpm vitest

# Jest
npm install -D jest @types/jest ts-jest
npx jest

Python

pip install pytest pytest-cov pytest-xdist

pytest
pytest --cov=src
pytest -n auto  # Paralelo

Java

# JUnit 5 (via Maven/Gradle)
./gradlew test

# TestNG
mvn test

.NET

dotnet test
dotnet test --collect:"XPlat Code Coverage"

CI/CD Integration

GitHub Actions

# .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'

      - name: Install dependencies
        run: npm ci

      - name: Run unit tests
        run: npm test

      - name: Install Playwright
        run: npx playwright install --with-deps

      - name: Run E2E tests
        run: npx playwright test

      - uses: actions/upload-artifact@v4
        if: always()
        with:
          name: playwright-report
          path: playwright-report/

Comandos que Claude Code Ejecutará

# Playwright
npx playwright test
npx playwright test --ui
npx playwright codegen
npx playwright show-report

# Cypress
npx cypress run
npx cypress open

# API Testing
newman run collection.json
http GET https://api.example.com

# Performance
k6 run script.js
lhci autorun

# Unit tests
pnpm test
pytest
dotnet test
./gradlew test

# Coverage
pnpm test --coverage
pytest --cov

Verificación del Entorno

#!/bin/bash
echo "=== Verificación Entorno QA ==="

echo -e "\n--- E2E Testing ---"
npx playwright --version 2>/dev/null || echo "Playwright no instalado"
npx cypress --version 2>/dev/null || echo "Cypress no instalado"

echo -e "\n--- API Testing ---"
newman --version 2>/dev/null || echo "Newman no instalado"
http --version 2>/dev/null || echo "HTTPie no instalado"

echo -e "\n--- Performance ---"
k6 version 2>/dev/null || echo "k6 no instalado"

echo -e "\n--- Unit Testing ---"
npx vitest --version 2>/dev/null || echo "Vitest no instalado"
pytest --version 2>/dev/null || echo "pytest no instalado"

echo -e "\n=== Verificación Completa ==="

Recursos