简体   繁体   English

我如何才能将Cucumber步骤失败的屏幕截图准确地附加到“魅力”报告中,而不是在“拆卸”部分中?

[英]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.

相关问题 如何在使用 Cucumber 和 JUnit 时截屏并将其附加到 Allure 报告中? - How take screenshot and attach it to Allure report, while using Cucumber and JUnit? 如何在诱惑报告中附加自定义/现有屏幕截图? - How to attach custom/existing screenshot in allure report? 如何将屏幕截图附加到 cucumber java 中的范围报告 - How to attach screenshot to extent report in cucumber java Allure @Step 没有出现在诱惑报告中(Selenide TestNG Gradle Allure) - Allure @Step does not appear in the allure report (Selenide TestNG Gradle Allure) 如何使用@Step注释在魅力报告中打印长字符串? - How to Print a long String in Allure Report using @Step Annotation? 如何将 Cucumber JUnit 步骤标记为失败但继续 - How to mark Cucumber JUnit step as failed but continue 将控制台日志添加到 allure 报告中的每个步骤?(Java、Selenium、TestNG、Cucumber) - Add console log to each step in allure report?(Java, Selenium, TestNG, Cucumber) 如何将屏幕截图附加到 azure 报告 selenium java Z1441F19754330CA4638BFDFAZEA - How to attach screenshot to azure report for selenium java cucumber Selenide:Allure 报告中缺少@Step 注释 - Selenide: missing @Step annotation in Allure report Cucumber 范围报告 - 如何将失败案例的屏幕截图添加到范围报告 - Cucumber extent report - how to add screenshot of failed case to the extent report
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM