5

我正在我的项目中实现名为TestListenerAdapter的自定义测试侦听器,并且我编写了代码以在侦听器类的 onTestFailure 方法中捕获屏幕截图。我还创建了以下方法,我正在调用 OnTestFailure 方法:

@Attachment(type = "image/png")
private byte[] createAttachment() {
    return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
}

public void onTestFailure(ITestResult result)
{
  createAttachment();
}

上述方法不会将屏幕截图附加到 Allure 报告中。

如果我们在 @Test 方法中调用 createAttachment() 方法,那么只会将屏幕截图添加到诱惑报告中。在每个@Test 中添加屏幕截图方法是一项繁重的任务,因此我在 TestNG 侦听器中实现了此方法,以便在测试用例失败时捕获屏幕截图。

请让我知道是否有一种方法可以从 TestListenerAdapter 侦听器的 onTestFailure() 方法中使用上述 createAttachment() 方法。

4

0 回答 0