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

如何在GitHub Actions中提取Playwright-Zephyr测试周期链接并复用?

在GitHub Actions中提取Playwright-Zephyr测试周期链接并用于Teams通知

实现步骤

1. 运行Playwright测试并保存日志

先修改测试运行步骤,把控制台输出保存到日志文件,方便后续提取内容:

- name: Run Playwright tests with Zephyr reporter
  id: run-playwright-tests
  run: npx playwright test > test-execution.log 2>&1
  env:
    # 配置你的Zephyr环境变量(如项目密钥、API令牌等)
    ZEPHYR_PROJECT_KEY: ${{ secrets.ZEPHYR_PROJECT_KEY }}
    ZEPHYR_API_TOKEN: ${{ secrets.ZEPHYR_API_TOKEN }}

2. 从日志中提取测试周期链接

添加步骤,用grep和sed匹配并提取链接,再设置为GitHub Actions输出变量:

- name: Extract Zephyr test cycle URL
  id: extract-cycle-url
  if: always()  # 即使测试失败也执行此步骤
  run: |
    # 根据插件实际输出的日志格式调整匹配字符串
    # 假设日志行格式为:"Zephyr test cycle created: https://your-zephyr-url/testcycle/xxx"
    CYCLE_URL=$(grep -o 'Zephyr test cycle created: https://[^[:space:]]*' test-execution.log | sed 's/Zephyr test cycle created: //')
    # 将提取到的链接写入GitHub Actions输出
    echo "cycle_url=$CYCLE_URL" >> $GITHUB_OUTPUT

注意:要根据playwright-zephyr实际输出的日志文本调整grep中的匹配前缀(比如如果日志是"Test cycle URL: ..."就替换对应的字符串)。

3. 发送Teams通知并引用链接

最后用Teams通知动作,把提取到的链接插入到通知内容里:

- name: Send Teams notification with test cycle link
  if: always()
  uses: microsoft/teams-action@v1
  with:
    webhook-url: ${{ secrets.TEAMS_WEBHOOK_URL }}
    title: "Playwright Test Execution Completed"
    message: |
      测试执行已完成,查看Zephyr测试周期:
      [点击查看测试周期](${{ steps.extract-cycle-url.outputs.cycle_url }})

关键说明

  • if: always():保证即使测试失败,提取链接和发送通知的步骤依然会执行
  • 日志匹配规则:必须和playwright-zephyr实际输出的日志格式一致,否则无法正确提取链接
  • 环境变量:要确保GitHub仓库的Secrets中已配置好Zephyr和Teams的相关密钥/令牌

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 16:43:18