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

标签 java maven junit webpage-screenshot allure

我一直在玩弄 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/

相关文章:

java - Android - 从 url 下载 JSON 文件

java - 从另一个 portlet (Liferay + Spring) 获取 Portlet Application Context

java - Maven Eclipse Tomcat ClassNotFoundException 异常

java - 使用主要资源而不是测试资源进行 Scalatest

java - JUnit异常 "Object is not an instance of declaring method"

java - 在运行 gradle eclipse 任务之前是否需要关闭 Eclipse?

java - 当设备方向更改为水平时,LinearLayout 按钮不出现?

java - 在 java maven jacoco : Failed to execute goal org. apache.maven.plugins :maven-surefire-plugin:2. 12.4:test 中执行测试时出错

java - 在 NetBeans IDE 中使用 gradle 和 tomcat 运行多个 war

java.lang.NoClassDefFoundError : org/hamcrest/SelfDescribing using Maven 错误