简体   繁体   English

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

[英]Using Allure to capture a screenshot on fail

I've been playing around with the Allure framework and I think that if any error/failure happened (basically anything that isn't a pass) I'd like to capture a screenshot. 我一直在玩Allure框架,我认为如果发生任何错误/失败(基本上任何不是通过),我想捕捉截图。

I'm using Java/Junit/Maven. 我正在使用Java / Junit / Maven。

I've seen there are various ways of using @Rule to do this, but wasn't sure if this would save the screenshot within the report. 我已经看到有各种方法使用@Rule来做到这一点,但不确定这是否会在报告中保存屏幕截图。

I had thought there would be a testcase status or something I could check as part of the tear down but counldn't find anything. 我以为会有一个测试用例状态或者我可以检查作为拆除的一部分,但是没有找到任何东西。

Anyone have any ideas? 有人有主意吗?

JUnit rules it is the default way to save screenshots on fail. JUnit规则它是在失败时保存屏幕截图的默认方式。 An example: 一个例子:

@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);
    }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM