Serenity自动化并行执行时Cucumber报告为空及Xray同步异常
问题解决方案
一、修复空报告问题
1. 移除冲突的JUnit注解
@RunWith(Cucumber.class)是JUnit 4的注解,和JUnit 5的@Suite注解冲突,会导致执行逻辑异常,直接影响报告输出。修改后的TestSuite代码:
@Suite @IncludeEngines("cucumber") @SelectClasspathResources("/features/sd/Tests") @CucumberOptions( plugin = { "pretty", "rerun:rerun.txt" } ) public class TestSuite {}
2. 统一插件配置,避免并行写入冲突
并行执行时,Cucumber自带的html/json插件不是线程安全的,多线程写入同一文件会导致内容为空或被覆盖。改用Serenity的并行报告能力:
- 保留
junit-platform-properties中的SerenityReporterParallel配置:
cucumber.execution.parallel.enabled=true cucumber.execution.parallel.config.strategy=fixed cucumber.execution.parallel.config.fixed.parallelism=3 cucumber.execution.parallel.config.fixed.max-pool-size=3 cucumber.plugin=io.cucumber.core.plugin.SerenityReporterParallel, rerun:rerun.txt
- 在
serenity.properties中添加配置,让Serenity生成合并后的Cucumber JSON报告:
serenity.cucumber.json.report.path=target/serenity-reports/cucumber-report.json
3. 验证报告生成
执行测试后,检查两个关键路径:
target/site/serenity:Serenity原生的HTML报告,包含所有场景执行结果target/serenity-reports/cucumber-report.json:合并后的Cucumber JSON报告,用于Xray同步
二、修复Xray同步无测试项问题
1. 关联测试场景与Xray工单
给每个Scenario添加对应Xray测试用例ID的标签,比如:
@TEST-123 Scenario: 用户登录功能验证 Given 用户打开系统登录页面 When 用户输入正确的账号密码 Then 成功跳转至首页
2. 确保GitLab流水线使用正确的报告文件
同步Xray的脚本要指向Serenity生成的完整JSON报告,示例curl命令:
curl -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_XRAY_TOKEN" \ --data-binary @target/serenity-reports/cucumber-report.json \ https://xray.yourdomain.com/api/v2/import/execution/cucumber
3. 检查报告格式兼容性
确认生成的JSON报告符合Xray要求的Cucumber格式,包含id(对应标签中的测试用例ID)、name、status等关键字段。
内容的提问来源于stack exchange,提问作者shivam
相关产品推荐
相关产品推荐

