gpt4 book ai didi

java - 使用 Allure 在失败时捕获屏幕截图

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:44:34 24 4
gpt4 key购买 nike

我一直在玩弄 Allure 框架,我认为如果发生任何错误/失败(基本上任何不合格的事情)我都想截屏。

我正在使用 Java/Junit/Maven。

我看到有多种使用@Rule 来执行此操作的方法,但不确定这是否会在报告中保存屏幕截图。

我原以为会有测试用例状态或一些我可以在拆卸过程中检查的东西,但找不到任何东西。

有人有什么想法吗?

最佳答案

JUnit 规定它是失败时保存屏幕截图的默认方式。一个例子:

@Rule
public TestWatcher screenshotOnFailure = new TestWatcher() {
@Override
protected void failed(Throwable e, Description description) {
makeScreenshotOnFailure();
}

@Attachment("Screenshot on failure")
public byte[] makeScreenshotOnFailure() {
return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
}
};

关于java - 使用 Allure 在失败时捕获屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29058832/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com