Skip to content

Repository files navigation

Playwright UI 自动化测试模板

这是一个基于 JavaScript/Node.js 的通用 UI 自动化测试基础模板,采用 Page Object Model(POM)组织页面交互,默认支持 Chromium 与 Firefox。

目录说明

  • tests/:测试场景。
  • pages/:页面对象;新增业务页面时继承或复用 BasePage
  • fixtures/:测试夹具;失败时将截图写入 screenshots/ 并附加到报告。
  • utils/:通用工具,例如测试产物命名与保存。
  • reports/html/:Playwright HTML 报告。
  • reports/test-results/:执行产物与 trace 文件。
  • screenshots/:失败时自动保存的全页截图。

生成的报告、trace 和截图默认不提交到 Git;目录中的 .gitkeep 用于保留标准产物结构,避免将测试数据或页面内容误上传。

安装

npm install
npx playwright install chromium firefox

如 Linux 缺少系统依赖且具备 sudo 权限,可执行:

npx playwright install --with-deps chromium firefox

执行

npm test
npm run test:chromium
npm run test:firefox

打开 HTML 报告:

npm run report

配置自定义

  • 设置 BASE_URL 可替换默认的 https://example.com
  • pages/ 添加业务页面对象,并从 tests/ 中调用。
  • 已启用 trace: 'on' 与失败自动截图;失败产物会同时在 HTML 报告中可查看。

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages