记者
上传结果到 Playwright 报告服务器的 Playwright 记者 - https://github.com/Cyborg Tests/playwright-reports-server 页面存档备份,存于互联网档案馆
安装
npm i -D @cyborgtests/reporter
基本配置
在你身边 playwright.config.ts 或者说 playwright.config.js数字 :
reporter: [
// blob reporter is required, produced zip would be uploaded
['blob', { outputFile: 'test-results/blob.zip' }],
[
'@cyborgtests/reporter',
{
// true by default. Use this if you need to skip this reporter for some cases (local executions for example)
enabled: true,
/**
* Your server url
* @see https://github.com/CyborgTests/playwright-reports-server
*/
url: 'https://your server instance.com',
// Set token if your server instance has authentication enabled
token: '1234',
// Timeout for reporter HTTP requests to finish, default 60000ms, increase if you have slow server and big requests.
requestTimeout: 60000,
// Relative path to your blob. Required.
reportPath: 'test-results/blob.zip',
// Any custom metadata to attach to this blob (strings)
resultDetails: {
branch: process.env.CI_COMMIT_BRANCH,
foo: 'bar',
bar: 'baz'
},
// Automatically trigger HTML report generation after tests finish. Shards supported. false by default
triggerReportGeneration: false
},
],
],
那就做你的测试 如果你看到 [ReporterPlaywrightReportsServer] 🎭 HTML Report is available at: ... - 您的blob结果已成功发送到服务器!
硬块
在所有硬盘完成后自动生成报告得到支持。 但你必须说明 testRun 财务报告和审定财务报表 triggerReportGeneration: true数字 :
- 在记者配置通过中
resultDetails: {
...
// testRun required, it should be same for all shards!
testRun: 'my-awesome-test-run-12'
...
},
triggerReportGeneration: true
记者将当前硬度数和总硬度数传递给服务器, 在上传了所有硬度后 - 报告会由服务器生成, 用于此中的所有 blobs testRun
测试检疫特性
测试检疫功能允许您自动跳过从Playwright Reports Server UI直接被标记为不稳定或片面的测试. 这有助于防止不稳定的测试阻断你的CI/CD管道.
如何运作
- 在Playwright Reports服务器中,测试通过网络UI(分析页面)或自动(如果设置页面上指定)被标记为隔离
- 测试执行前,记者从服务器获取隔离测试列表
- 记者将此列表写入本地的 JSON 文件
- 在进行试验时,每次试验都要对照检疫清单进行
- 以存储在服务器中的原因自动跳过检疫测试
启用测试检疫
为了能够自动跳过隔离试验:
- 导入扩展
test从记者包中固定 - 启用
skipQuarantinedTests在记者配置中 - 使用扩展
test在您的配置中设置
import { defineConfig } from '@playwright/test';
import { test } from '@cyborgtests/reporter';
export default defineConfig({
reporter: [
['blob', { outputFile: 'test-results/blob.zip' }],
[
'@cyborgtests/reporter',
{
url: 'http://localhost:3000',
reportPath: 'test-results/blob.zip',
// Specify the project name to fetch quarantined tests for
resultDetails: {
project: 'my-project',
},
// Enable test quarantine
skipQuarantinedTests: true,
// Optional: Custom path for the quarantine file (default: './quarantine.json')
quarantineFilePath: './quarantine.json',
},
],
],
// Use the extended test fixture that checks quarantine status
test: test,
});
这个 checkQuarantine 固定线
记者输出扩展 test 包括一个 checkQuarantine 钩子负责检查测试是否隔离.
配置选项
| 选项 | 类型 | 默认 | 说明 |
|---|---|---|---|
skipQuarantinedTests | 布尔 | false | 允许自动跳过隔离测试 |
quarantineFilePath | 字符串 | './quarantine.json' | 隔离列表的存储路径 |
测试执行期间发生的情况
何时 skipQuarantinedTests 启用 :
-
测试开始前 (单位:千美元)
onBegin:- 记者收集隔离检验
/api/tests?status=quarantined&project=<your_project> - 结果写入
quarantineFilePath
- 记者收集隔离检验
-
每次试验期间 (单位:千美元)
checkQuarantine固定线:- 固定读取隔离文件
- 检查是否
testId匹配任何隔离测试ID - 如果匹配则跳过测试
-
测试完成 (单位:千美元)
onEnd:- 结果被上传到服务器
- 如果
triggerReportGeneration真实
解决问题
未找到警告的检疫文件 :
[checkQuarantinedTests] Quarantine file not found at ./quarantine.json, proceeding without skipping tests.
确保记者可以从服务器上获取隔离测试(检查网络和认证).
测试未跳过 :
- 校验
skipQuarantinedTests: true设定 - 验证您正在使用扩展
test固定线 :import { test } from '@cyborgtests/reporter' - 检查
project内resultDetails匹配服务器中的工程名称, 如果您没有此工程 - 它可以跳过 - 确保正确生成隔离文件
所有测试被跳过 :
- 检查服务器的测试管理阈值是否配置得当
- 验证测试在服务器 UI (分析页) 中被正确标记为隔离