@playwright-test-runner/core
v1.0.23
Published
Libreria per eseguire test Playwright con ricerca automatica dei test e visualizzazione report
Maintainers
Readme
Playwright Test Runner
Libreria per eseguire test Playwright con ricerca automatica dei test e visualizzazione report.
Caratteristiche
- Playwright Integrato - Include Playwright, non serve installarlo separatamente
- Preflight Browser Check - Verifica browser mancanti prima dei test con istruzioni chiare o installazione automatica
- Ricerca Automatica - Trova automaticamente i file di test nella cartella
tests/ - Report Interattivi - Visualizzazione automatica dei risultati nel browser
- Report Robusto - Se la porta
9323e occupata usa automaticamente una porta libera - Zero Config - Funziona subito, nessuna configurazione richiesta
- Setup Guidato - Crea automaticamente la cartella tests se non esiste
Installazione
npm install @playwright-test-runner/coreDurante l'installazione il package esegue un controllo browser Playwright:
- se i browser sono gia presenti, non fa nulla;
- se mancano, prova a installarli automaticamente.
- usa come default
PLAYWRIGHT_BROWSERS_PATH=$HOME/Library/Caches/ms-playwrightse la variabile non e impostata. - crea automaticamente
tests/,tests/example.spec.tsetests/playwright.config.ts. tests/playwright.config.tse una config locale agnostica del progetto consumer, usata direttamente dal runner.
Se vuoi disattivare questo comportamento:
PLAYWRIGHT_TEST_RUNNER_SKIP_BROWSER_INSTALL=1 npm install @playwright-test-runner/coreVariabili ambiente per config generata:
PLAYWRIGHT_BASE_URL(default:http://localhost:3000)PLAYWRIGHT_WEB_SERVER_COMMAND(default:npm run start)
Esempio rapido:
PLAYWRIGHT_BASE_URL=http://localhost:4200 npx playwright-test --ciIl runner usa la config locale del consumer:
tests/playwright.config.ts
Comandi Disponibili
npx playwright-test- Esegue i test (con preflight browser) e apre il reportnpx playwright-test --no-open-report- Esegue test senza avviare server reportnpx playwright-test --report-only-on-fail- Apre il report solo se i test falliscononpx playwright-test --ci- Modalita CI: esegue test e termina senza processi appesinpx playwright-test --install-browsers- Installa browser mancanti prima dell'esecuzionenpx playwright-test-install- Installa i browser Playwright dal package padrenpx playwright-report- Mostra solo il report (senza rieseguire i test)npx playwright-report --port 9400- Imposta una porta preferita (con fallback automatico se occupata)
Utilizzo
Eseguire i test
npx playwright-testQuesto comando:
- Cerca i file
*.spec.ts/*.test.tsnella cartellatests/ - Verifica che i browser Playwright siano disponibili
- Esegue tutti i test con Playwright
- Apre automaticamente il report nel browser (se non in CI e senza flag di disattivazione)
Se i browser non sono installati, il comando mostra un errore chiaro con suggerimento:
npx playwright installOppure puo installarli automaticamente:
npx playwright-test --install-browsersOppure con comando dedicato:
npx playwright-test-installModalita report
# Esegue test ma NON apre il server report
npx playwright-test --no-open-report
# Apre report solo se i test falliscono
npx playwright-test --report-only-on-fail
# Modalita CI: non apre report server e termina pulito
npx playwright-test --ciIn ogni modalita report, se la porta 9323 e occupata viene usata una porta libera automaticamente.
Se la cartella tests/ non esiste, il comando ti chiederà se vuoi crearla automaticamente con un file di test di esempio.
Visualizzare il report
npx playwright-reportApre il report HTML dell'ultima esecuzione su http://localhost:<porta>.
Se 9323 e gia in uso, viene selezionata automaticamente una porta disponibile.
# Usa una porta preferita diversa
npx playwright-report --port 9400Opzioni
# Specifica una cartella test diversa
npx playwright-test --tests-dir e2e
# Specifica la root del progetto
npx playwright-test --project /path/to/project
# Non aprire il report
npx playwright-test --no-open-report
# Apri report solo in caso di failure
npx playwright-test --report-only-on-fail
# Installa browser mancanti automaticamente
npx playwright-test --install-browsers
# Comando dedicato install browser
npx playwright-test-install
# Esecuzione CI (uscita pulita, nessun server in ascolto)
npx playwright-test --ci
# Mostra help
npx playwright-test --helpSetup Progetto
Struttura
your-project/
├── tests/ # Cartella dei test
│ ├── example.spec.ts
│ ├── login.spec.ts
│ └── api/
│ └── users.test.ts
├── package.json
└── playwright-report/ # Generato dopo i testEsempio di test
File tests/example.spec.ts:
import { test, expect } from '@playwright/test';
test('homepage has title', async ({ page }) => {
await page.goto('https://playwright.dev/');
await expect(page).toHaveTitle(/Playwright/);
});
test('health endpoint responds', async ({ request }) => {
const response = await request.get('/health');
expect(response.ok()).toBeTruthy();
});Uso Programmatico
import { PlaywrightTestRunner } from '@playwright-test-runner/core';
const runner = new PlaywrightTestRunner({
projectRoot: process.cwd(),
testsDir: 'tests'
});
// Ottieni lista dei test
const testFiles = await runner.getTestFiles();
console.log('Test trovati:', testFiles);
// Esegui i test
const result = await runner.runTests({
reporter: 'html',
headed: false,
installBrowsersIfMissing: true
});
if (result.success) {
// Mostra report
const { url } = await runner.showReport();
console.log('Report disponibile su:', url);
}
// Cleanup
runner.stopReportServer();Script package.json Consigliati
{
"scripts": {
"test": "playwright-test",
"test:report": "playwright-report",
"test:ci": "playwright-test --ci",
"test:local": "playwright-test --report-only-on-fail"
}
}CI/CD (GitHub Actions)
name: E2E Tests
on: [push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Install
run: npm install
- name: Install browsers
run: npx playwright install --with-deps chromium
- name: Run tests
run: npx playwright-test --ci
- name: Upload report
if: always()
uses: actions/upload-artifact@v3
with:
name: playwright-report
path: playwright-report/Requisiti
- Node.js >= 18
- Playwright - Incluso nella libreria
License
MIT
