IKivan-kozenko -aqa
Try yourself as a QA tester
All topics·Beginner·10 / 16

Command line

The flags I use every day: --grep to run a specific test by name, --last-failed to re-run only what broke, --project=firefox to test one browser, --debug to open Inspector and step through. On CI I always add --forbid-only so test.only() left in by accident fails the build.

Running tests — the commands I use most

The most common thing: run a specific file, filter by test title, or target one browser. I almost never run all tests locally — too slow. I run the specific test or file I'm working on.

bash
# Запустити всі тести
npx playwright test

# Конкретний файл
npx playwright test tests/orders.spec.ts

# За назвою тесту (regex)
npx playwright test -g "create order"

# Конкретний рядок у файлі
npx playwright test orders.spec.ts:42

# Конкретний проєкт (браузер)
npx playwright test --project=firefox

# Тільки те що впало востаннє
npx playwright test --last-failed

# Дебаг режим (відкрити Inspector)
npx playwright test --debug

# Інтерактивний UI mode
npx playwright test --ui

CI-specific flags

--forbid-only is the one I add on CI to prevent test.only() from accidentally running only one test — if someone commits a file with test.only, CI fails loudly instead of silently running only that test and passing everything green.

--only-changed runs only the test files affected by the current branch changes. Playwright analyzes import graphs — if I change orders.service.ts, it runs orders.spec.ts but not dashboard.spec.ts. Useful for fast PR feedback.

bash
# Провалити збірку якщо хтось залишив test.only()
npx playwright test --forbid-only

# Один воркер на CI (стабільніше на shared runners)
npx playwright test --workers=1

# Тільки тести змінені у поточному PR
npx playwright test --only-changed=origin/main

# Шардинг: цей job запускає 1/4 тестів
npx playwright test --shard=1/4

Output and debugging flags

--trace on forces trace recording for every test — useful when I want a trace for a specific passing test to understand what it's doing. On CI I use on-first-retry in the config instead.

bash
# Headed режим (бачити браузер)
npx playwright test --headed

# Записати трейс для всіх тестів
npx playwright test --trace on

# Запустити кожен тест 5 разів (перевірка на flakiness)
npx playwright test --repeat-each=5

# Зупинитись після першої невдачі
npx playwright test -x

# Зупинитись після 3 невдач
npx playwright test --max-failures=3

# Показати тести без запуску
npx playwright test --list

Show report and trace viewer

After tests finish, npx playwright show-report opens the HTML report in a browser. From there I can click on a failing test to see its trace, screenshots, and error details. I can also open a specific trace file or a downloaded CI artifact zip.

bash
# Відкрити останній звіт
npx playwright show-report

# Відкрити конкретну теку звіту
npx playwright show-report my-report/

# Відкрити zip з CI артефакту
npx playwright show-report playwright-report.zip

# Відкрити конкретний трейс
npx playwright show-trace test-results/my-test/trace.zip

Code generation and other tools

codegen opens a browser where every click and fill automatically generates test code. I use it to quickly get the locators for new UI elements — faster than writing getByRole() calls manually when I don't know the element structure.

bash
# Відкрити codegen (записує в буфер обміну)
npx playwright codegen

# Codegen з конкретного URL
npx playwright codegen http://localhost:3000/orders

# Генерувати Python-код
npx playwright codegen --target=python

# Встановити/оновити браузери
npx playwright install --with-deps

# Злити blob-звіти з шардів
npx playwright merge-reports --reporter html ./all-blob-reports

Full options reference

The complete list of CLI options for npx playwright test. I don't use most of these daily but they're useful to know.

bash
npx playwright test --help

# Найбільш корисні:
# --debug               Відкрити Playwright Inspector
# --headed              Запустити з видимим браузером
# -g, --grep            Фільтр за regex назви тесту
# --project             Запустити конкретний проєкт
# --ui                  Інтерактивний UI mode
# -j, --workers         Кількість паралельних воркерів
# --last-failed         Запустити тільки тести що впали
# --only-changed        Запустити тільки змінені тести
# --shard               Шард у форматі 1/4
# --repeat-each         Запустити кожен тест N разів
# --forbid-only         Провалити якщо є test.only()
# --trace               Режим запису трейсу
# --timeout             Тайм-аут тесту в мс
# --retries             Кількість повторів для flaky тестів
# -x                    Зупинитись після першої невдачі
# --update-snapshots    Оновити snapshot-очікування