Vik*_*kas 5 testng selenium-webdriver allure
我在项目中实现了名为TestListenerAdapter的自定义测试侦听器,并且编写了捕获侦听器类的onTestFailure方法中的屏幕截图的代码。我还创建了以下方法,并在OnTestFailure方法中进行调用:
@Attachment(type = "image/png")
private byte[] createAttachment() {
return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
}
public void onTestFailure(ITestResult result)
{
createAttachment();
}
Run Code Online (Sandbox Code Playgroud)
上述方法未将屏幕截图附加到“魅力”报告中。
如果我们在@Test方法中调用createAttachment()方法,则仅将屏幕截图添加到吸引力报告中。在每个@Test中添加屏幕截图方法是一项繁重的任务,因此我已经在TestNG侦听器中实现了此方法,以便在测试用例失败时捕获屏幕截图。
请让我知道是否有一种方法可以使用TestListenerAdapter侦听器的onTestFailure()方法中的上述createAttachment()方法。
对于与 TestNG 一起使用的 Allure 侦听器,您有 2 个选项:
@Listeners(MyAllureListener.class)
public class MyTestClass() {
...
}
Run Code Online (Sandbox Code Playgroud)

文件名必须与package.classname您扩展的侦听器匹配。该文件必须包含package.classname指向您的 Listener 类的行,即com.test.MyListener
| 归档时间: |
|
| 查看次数: |
2468 次 |
| 最近记录: |