[英]How I can attach screenshot of failed Cucumber step to Allure report exactly in step, not in Tear Down section?
I can't add screenshot of failed cucumber step under the step in Allure report. 我无法在“魅力”报告中的步骤下添加失败的黄瓜步骤的屏幕截图。
I use allure-cucumber4-jvm:2.12.1, cucumber-java:4.3.1 and try to add screenshot of tested web app to allure report EXACTLY under failed cucumber step. 我使用allure-cucumber4-jvm:2.12.1,cucumber-java:4.3.1并尝试添加经过测试的Web应用程序的屏幕截图以完全诱使黄瓜在失败的黄瓜步骤下生成报告。 So I tried to use cucumber's @AfterStep and @After annotations and add screenshot in annotated methods under scenario.isFailed() conditions. 因此,我尝试使用了黄瓜的@AfterStep和@After注释,并在case.isFailed()条件下在带注释的方法中添加了屏幕截图。 But the problem is that screenshots are added after all steps in Tear Down section. 但是问题在于,在“拆解”部分中的所有步骤之后都添加了屏幕截图。 The only difference is that @After method is called once and @AfterStep methods is called by every step. 唯一的区别是@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) {}
}
}
I expect screenshot of tested web app exactly under failed cucumber step? 我希望测试的Web应用程序的屏幕截图恰好在失败的黄瓜步骤下执行? but actually I have it in Tear Down section after all scenario 但实际上在所有情况下我都在“拆机”部分中
Idea is using the events to capture the step status and embed the screenshot. Idea正在使用事件捕获步骤状态并嵌入屏幕截图。 If I am correct, As per current design AfterStep
does not execute when the step is failed. 如果我是正确的,则根据当前设计,如果步骤失败,则不会执行AfterStep
。 So we have to use AfterConfiguration in hooks. 因此,我们必须在挂钩中使用AfterConfiguration。
Ruby: Here is the ruby implementation. Ruby:这是ruby的实现。
AfterConfiguration do |scenario, config|
config.on_event :test_step_finished do |event|
if event.result.failed?
# get screenshot
end
end
end
Check this thread regarding the allure implementation. 检查此线程有关诱惑的实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.