门墩儿自动化测试

lifanagju_citu 0d7b8562a8 使用Codegen录制用户操作并自动生成测试代码 1 month ago
.vscode 0d7b8562a8 使用Codegen录制用户操作并自动生成测试代码 1 month ago
files b83566ce46 playwright初始化 1 month ago
tests-examples b83566ce46 playwright初始化 1 month ago
.env b83566ce46 playwright初始化 1 month ago
.gitignore b83566ce46 playwright初始化 1 month ago
README.md 0d7b8562a8 使用Codegen录制用户操作并自动生成测试代码 1 month ago
env.config.js b83566ce46 playwright初始化 1 month ago
package.json b83566ce46 playwright初始化 1 month ago
playwright.config.js b83566ce46 playwright初始化 1 month ago

README.md

Playwright 执行脚本命令大全

分类排序:高频 -> 低频

npx playwright --help 可查看完整选项列表。

1. 高频命令(日常测试执行)

npx playwright test # 运行所有测试(默认 Chromium) npx playwright test tests/login.spec.js # 运行指定测试文件 npx playwright test --grep "login test" # 运行匹配名称的测试 npx playwright test --grep @smoke # 运行带标签的测试(如 @smoke) npx playwright test --grep-invert "@slow" # 排除特定标签的测试 npx playwright test --ui # 启动 UI 模式(交互式调试) npx playwright test --debug # 调试模式(禁用无头模式)

2. 中频命令(浏览器 & 环境控制)

npx playwright test --browser=firefox # 指定浏览器(chromium|firefox|webkit) npx playwright test --browser=all # 在所有浏览器上运行 npx playwright test --project=Mobile # 运行指定项目(需配置) npx playwright test --config=custom.config.js # 指定自定义配置 npx playwright test --ci # CI 模式(自动检测环境) npx playwright test --headed # 强制显示浏览器(禁用无头模式)

3. 中频命令(报告 & 输出)

npx playwright show-report # 生成并打开 HTML 报告 npx playwright test --reporter=junit # 生成 JUnit 报告(CI 友好) npx playwright test --reporter=json # 生成 JSON 报告 npx playwright test --verbose # 显示详细日志 npx playwright test --quiet # 静默模式(减少输出)

4. 低频命令(测试维护)

npx playwright test --update-snapshots # 更新测试快照 npx playwright test --update-snapshots=fail # 仅更新失败的快照 npx playwright test --retries=3 # 失败时自动重试 npx playwright test --repeat-each=2 # 重复运行测试(非失败重试) npx playwright test --workers=2 # 设置并发 worker 数量 npx playwright test --workers=1 # 禁用并发(串行运行)

5. 低频命令(安装 & 初始化)

npx playwright install # 安装所有支持的浏览器 npx playwright install chromium # 仅安装 Chromium npx playwright install --with-deps # 安装浏览器及系统依赖 npx playwright codegen example.com # 启动代码生成器(录制测试) npx playwright codegen --browser=firefox # 在指定浏览器录制

6. 低频命令(高级 & 调试)

npx playwright test --timeout=60000 # 设置全局超时(毫秒) npx playwright test --slowmo=1000 # 慢速模式(延迟操作) npx playwright test tests/login.spec.js:10 # 运行文件中特定测试块 npx playwright --help # 打印所有可用命令

使用Codegen录制用户操作并自动生成测试代码

启动后会打开两个窗口:

1.浏览器窗口:用于实际操作,点击、输入等。2.Playwright Inspector 窗口:显示生成的代码

在浏览器窗口输入目标网站地址。

npx playwright codegen # 启动 Codegen。 npx playwright codegen example.com # 指定录制目标网站