命令行
简介
以下是命令行中最常见的选项。
-
运行所有的测试
npx playwright test
-
运行单个测试文件
npx playwright test tests/todo-page.spec.ts
-
运行一组测试文件
npx playwright test tests/todo-page/ tests/landing-page/
-
运行文件名包含
my-spec
或者my-spec-2
npx playwright test my-spec my-spec-2
-
运行
my-specs.ts
中第 42 行中的测试npx playwright test my-spec.ts:42
-
运行带有指定标题的测试
npx playwright test -g "add a todo item"
-
在有头的浏览器中运行测试
npx playwright test --headed
-
运行特定项目所有测试
npx playwright test --project=chromium
-
禁用并行化
npx playwright test --workers=1
-
选择报告
npx playwright test --reporter=dot
-
在调试模式下运行 Playwright 检查器
npx playwright test --debug
-
在交互式 UI 模式下运行测试,内置观察模式(预览)
npx playwright test --ui
-
请求帮助
npx playwright test --help
参考
Playwright Test 的完整选项集可以在配置文件中找到。以下选项可以通过命令行传递,并优先于配置文件中的设置:
选项 | 描述 |
---|---|
Column 1, row 1 |
Column 2, row 1 |
Column 1, row 2 |
Column 2, row 2 |
Column 1, row 3 |
Column 2, row 3 |
Column 1, row 4 |
Column 2, row 4 |
Column 1, row 5 |
Column 2, row 5 |
Column 1, row 6 |
Column 2, row 6 |
Column 1, row 7 |
Column 2, row 7 |
Column 1, row 8 |
Column 2, row 8 |
Column 1, row 9 |
Column 2, row 9 |
Column 1, row 10 |
Column 2, row 10 |