selenium - 我无法将屏幕截图附加到范围报告。解决办法是什么?
问题描述
@AfterMethod
public void getResult(ITestResult result) throws Exception{
if(result.getStatus() == ITestResult.FAILURE)
{
extentlogger.log(Status.FAIL, MarkupHelper.createLabel(result.getThrowable() +
" - Test Case Failed", ExtentColor.RED));
try {
// get path of captured screenshot using custom failedTCTakeScreenshot method
String screenshotPath = takeSnapShot(result);
extentlogger.fail("Test Case Failed Snapshot is below " +
extentlogger.addScreenCaptureFromPath(screenshotPath));
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
上面的代码是我在TestNG中使用after方法的代码。我做错什么了吗?在此处输入图像描述
解决方案
您没有任何名为 takeSnapShot 或未声明为公共的方法:
在基类中创建一个具有以下内容的方法,或者通过替换 takeSnapShot 步骤直接在 aftermethod 挂钩中添加以下代码:
//Convert web driver object to TakeScreenshot
TakesScreenshot scrShot =((TakesScreenshot)webdriver);
//Call getScreenshotAs method to create image file
File SrcFile=scrShot.getScreenshotAs(OutputType.FILE);
//Move image file to new destination
File DestFile=new File(fileWithPath);
//Copy file at destination
FileUtils.copyFile(SrcFile, DestFile);
推荐阅读
- c# - 如何在并行任务中运行 Microsoft Solver Foundation
- javascript - 即使明确返回承诺,React 函数也不会返回承诺(Firebase 存储)
- angular - 如何以角度渲染不同的组件?
- python - 我如何用 b4s 获得这个号码?
- r - r cor spearman 处理缺失值
- r - 遍历数据框时为空 ggplot
- css - 如何去除页面右侧的空白
- session - 我们可以使用现有的 OWASP ZAP 会话来测试新版本吗?
- linux - 如何在匹配第一次出现的单词之间打印所有行?
- react-native - 当用户在 react-native 中输入任何值时如何在 TextInput 中添加“$”符号