You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将Playwright自动化测试结果推送至MS Teams?能否用test-results-reporter?

关于test-results-reporter适配Playwright并发送Teams通知的方案

完全可以用test-results-reporter适配Playwright测试框架,实现测试完成后向MS Teams发送通知,具体实现步骤如下:

  1. 生成Playwright兼容格式的测试报告
    Playwright默认支持生成JUnit格式报告,这是test-results-reporter兼容的核心格式。运行测试时添加参数指定报告类型和输出路径:
    npx playwright test --reporter=junit --output=test-results/junit.xml
    执行后会在test-results目录下生成junit.xml测试结果文件。

  2. 安装test-results-reporter
    在项目中安装该npm包:
    npm install test-results-reporter --save-dev

  3. 配置通知规则
    在项目根目录创建test-results-reporter.config.js配置文件,填入Teams通知和报告解析规则:

module.exports = {
  report: [
    {
      type: 'teams',
      options: {
        webhookUrl: '你的MS Teams机器人Webhook地址',
        title: 'Playwright UI自动化测试结果',
        message: '本次流水线测试已完成,结果汇总如下',
        showFailedTests: true,
        showPassedTests: false,
        showSkippedTests: true
      }
    }
  ],
  results: [
    {
      type: 'junit',
      files: './test-results/junit.xml'
    }
  ]
};
  1. 在Azure DevOps流水线中添加通知步骤
    在Playwright测试执行完成的步骤后,新增npm脚本执行步骤,运行通知命令:
    npx test-results-reporter publish -c test-results-reporter.config.js

注意事项

  • 确保Azure DevOps流水线环境已安装Node.js和npm,可正常运行Playwright及相关依赖
  • 将Teams Webhook地址存入Azure DevOps变量组,避免硬编码泄露敏感信息
  • 可通过调整配置文件中的参数,自定义通知标题、内容及测试结果展示范围

内容的提问来源于stack exchange,提问作者Azman Sabbir

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 16:15:43