Files
doxa/doxa-notes/docs/startTest.md
T
2026-08-07 09:48:59 +02:00

71 lines
1.8 KiB
Markdown

1. Upravit `plawright.config.ts` (doxa)
2. Do `package.json` přidat script BASE_URL (doxa)
3. Upravit HomePage.ts a další dle (doxa)
---
## Spuštění testů
- local `npx playwright test --ui` nebo `npx playwright test`
- prod `test:prod` nebo dle nastavení script v `package.json`
---
script package.json:
```
"scripts": {
"test": "playwright test",
"test:prod": "BASE_URL=https://doxa-notes.org playwright test homePage.test.ts",
"test:prodapp": "BASE_URL=https://app.doxa-notes.org playwright test noteApp.test.ts "
}
```
playwright.config.ts:
```
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
testDir: './tests',
fullyParallel: true,
reporter: 'html',
use: {
// Pokud v terminálu nastavíš BASE_URL, použije ho. Jinak použije localhost.
baseURL: process.env.BASE_URL || 'http://localhost:8080',
trace: 'on-first-retry',
},
webServer: {
// WebServer se spustí pouze tehdy, pokud NENÍ nastavena jiná BASE_URL
// (nechceme spouštět lokální server, když testujeme produkci)
command: process.env.BASE_URL ? undefined : 'npx http-server ../../ -p 8080',
url: process.env.BASE_URL || 'http://localhost:8080',
reuseExistingServer: !process.env.CI,
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
],
});
```
HomePage.test.ts:
```
readonly page: Page;
constructor(page: Page) {
this.page = page;
}
// Přidej metodu pro navigaci na konkrétní soubor
async navigate(file: string = 'index.html') {
// Pokud jsme na lokálu, přidáme složku /web/
// Pokud jsme na produkci, předpokládáme root /
const prefix = process.env.BASE_URL?.includes('doxa-notes.org') ? '' : 'web/';
await this.page.goto(`${prefix}${file}`);
}
```