如何在Geb中使用Athaydes插件仅为失败步骤截图
解决Athaydes Spock报告插件仅捕获失败步骤截图的问题
我刚好熟悉这个插件的配置逻辑,你只需要在现有的配置文件中添加一行属性就能实现需求:
- 在
com.athaydes.spockframework.report.IReportCreator.properties末尾加入以下配置:com.athaydes.spockframework.report.screenshot.onlyOnFailure=true
这个配置项的作用非常明确:它会告诉插件仅当测试步骤执行失败时才捕获并嵌入截图,成功的测试步骤不会生成任何截图,完全匹配你的需求。
修改后的完整配置文件示例如下:
# Name of the implementation class of the report creator com.athaydes.spockframework.report.IReportCreator=com.athaydes.spockframework.report.template.TemplateReportCreator # Output directory (where the spock reports will be created) - relative to working directory com.athaydes.spockframework.report.outputDir=target/reports com.athaydes.spockframework.report.testSourceRoots=src/test/groovy com.athaydes.spockframework.report.showCodeBlocks=false # Set properties specific to the TemplateReportCreator com.athaydes.spockframework.report.template.TemplateReportCreator.specTemplateFile=/templates/spec-template.html com.athaydes.spockframework.report.template.TemplateReportCreator.reportFileExtension=html com.athaydes.spockframework.report.template.TemplateReportCreator.summaryTemplateFile=/templates/summary-template.html com.athaydes.spockframework.report.template.TemplateReportCreator.summaryFileName=index.html # 新增:仅在失败步骤捕获截图 com.athaydes.spockframework.report.screenshot.onlyOnFailure=true
保存配置后重新运行测试,生成的HTML报告就只会包含失败步骤的截图了。如果你的截图逻辑是自定义实现的,可能需要额外在扩展代码中判断测试执行状态,但使用插件自带的截图功能时,这一行配置就足够生效啦。
内容的提问来源于stack exchange,提问作者Durgesh
相关产品推荐
相关产品推荐

