
[英]How take screenshot and attach it to Allure report, while using Cucumber and JUnit?
[英]How I can attach screenshot of failed Cucumber step to Allure report exactly in step, not in Tear Down section?
我无法在“魅力”报告中的步骤下添加失败的黄瓜步骤的屏幕截图。
我使用allure-cucumber4-jvm:2.12.1,cucumber-java:4.3.1并尝试添加经过测试的Web应用程序的屏幕截图以完全诱使黄瓜在失败的黄瓜步骤下生成报告。 因此,我尝试使用了黄瓜的@AfterStep和@After注释,并在case.isFailed()条件下在带注释的方法中添加了屏幕截图。 但是问题在于,在“拆解”部分中的所有步骤之后都添加了屏幕截图。 唯一的区别是@After方法仅被调用一次,而@AfterStep方法则被每个步骤调用。
@AfterStep
public void addScreenshotOnFailed(Scenario scenario) throws IOException {
if (scenario.isFailed()) {
try {
Allure.addAttachment("Failed step", new FileInputStream(Screenshots.takeScreenShotAsFile()));
} catch (FileNotFoundException ignored) {}
}
}
我希望测试的Web应用程序的屏幕截图恰好在失败的黄瓜步骤下执行? 但实际上在所有情况下我都在“拆机”部分中
Idea正在使用事件捕获步骤状态并嵌入屏幕截图。 如果我是正确的,则根据当前设计,如果步骤失败,则不会执行AfterStep
。 因此,我们必须在挂钩中使用AfterConfiguration。
Ruby:这是ruby的实现。
AfterConfiguration do |scenario, config|
config.on_event :test_step_finished do |event|
if event.result.failed?
# get screenshot
end
end
end
检查此线程有关诱惑的实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.