![](/img/trans.png)
[英]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.