
QAF 4.x 默认不兼容 allure-cucumber 系列插件,需改用 allure-testng 并配合 QAF 的 @Step 注解与自定义适配器,才能生成含结构化步骤的 Allure JSON 报告。
qaf 4.x 默认不兼容 allure-cucumber 系列插件,需改用 allure-testng 并配合 qaf 的 `@step` 注解与自定义适配器,才能生成含结构化步骤的 allure json 报告。
在 QAF(v4.0.0-RC1 及以上)中直接引入 allure-cucumber5-jvm 无法生成有效 Allure 报告,原因在于:QAF 并非基于 Cucumber 实现 BDD,其 @Test 方法调用的是 QAF 自研的 QAFTestNGListener 和 ScenarioEngine,不触发 Cucumber 的钩子(如 @Before, @Given),因此 allure-cucumber* 依赖完全无效——即使配置了 allure.results.directory,也只会输出空目录或零星元数据,无实际测试步骤 JSON。
✅ 正确方案:使用 allure-testng + QAF 原生能力适配
首先,在 pom.xml 中替换依赖并确保版本兼容(Allure 2.23.0 支持 TestNG 7.8+,QAF 4.0.0-RC1 推荐搭配 TestNG 7.9+):
<dependency><groupid>io.qameta.allure</groupid><artifactid>allure-testng</artifactid><version>2.23.0</version><scope>test</scope></dependency>
同时,在 maven-surefire-plugin 中显式配置 Allure 结果路径与监听器:
<plugin><groupid>org.apache.maven.plugins</groupid><artifactid>maven-surefire-plugin</artifactid><version>3.2.5</version><configuration><suitexmlfiles><suitexmlfile>testng.xml</suitexmlfile></suitexmlfiles><properties><property><name>listener</name><value>io.qameta.allure.testng.AllureTestNG</value></property></properties><!-- 关键:指定 Allure 结果输出目录 --><systempropertyvariables><allure.results.directory>${project.basedir}/allure-results</allure.results.directory></systempropertyvariables></configuration></plugin>
⚠️ 注意事项:
- QAF 的
@Step注解(com.qmetry.qaf.automation.step.Step)可被AllureTestNG自动识别为 Allure 步骤,但需确保方法签名规范(如无重载、返回 void 或支持序列化的对象); - 若需增强步骤粒度(例如将 QAF 的
getDriver().get(...)自动记录为步骤),建议封装带@Step的工具方法,而非依赖底层 WebDriver 调用; - 避免混用
allure-cucumber*和allure-testng,二者监听器冲突会导致报告生成失败; - 执行命令应为:
mvn clean test && allure generate allure-results -o allure-report --clean。
? 进阶提示:如需完整行为驱动视图(Feature/Scenario/Step 层级),可结合 QAF 的 @QAFTest + @MetaData 注解模拟 Feature 标签,并在 allure-results 生成后通过 allure plugin 或自定义 AllureLifecycle 扩展注入 @feature、@story 等标签。
最终验证:运行测试后检查 allure-results/ 目录下是否生成 .json 文件(如 test-suite-result.json, xxx-step-result.json),再执行 allure serve allure-results 即可打开交互式报告——此时每个 QAF 测试方法将作为 TestCase 显示,其内部 @Step 方法将展开为可折叠的详细步骤,真正实现 QAF 与 Allure 的深度集成。










