macos - 无法将屏幕截图保存在指定路径或将屏幕截图附加到 MAC 中的 extentreports
问题描述
我尝试了很多方法来截取测试用例失败的屏幕截图,但没有任何效果。使用 selenium 时无法截取屏幕截图并将其附加到 MAC os 中的 extentreport。
public void onTestFailure(ITestResult tr)
{
logger=extent.createTest(tr.getName()); // create new entry in the report
logger.log(Status.FAIL,MarkupHelper.createLabel(tr.getName(),ExtentColor.RED)); // send the passed information to the report with GREEN color highlighted
String screenshotPath="./Stest-output/"+tr.getName()+".png";
TakesScreenshot ts = (TakesScreenshot)driver;
File img =ts.getScreenshotAs(OutputType.FILE);
File destination =new File(screenshotPath);
try {
FileUtils.copyFile(img,destination);
logger.addScreenCaptureFromPath(screenshotPath);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if(img != null)
{
System.out.println("Screenshot is below:"+tr.getName());
try {
logger.info("Screenshot is below:" + logger.addScreenCaptureFromPath(screenshotPath));
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
尝试将图像从源复制到目标时抛出空指针异常。
使堆栈溢出中的所有方法都可用。
解决方案
您无法将屏幕截图附加到范围报告 html 中,因为您忘记调用flush()
将报告 HTML 文件附加到所有测试结果/屏幕截图的方法。必须至少有一个结束的测试才能附加到报告中。
注意:如果flush()
在任何结束的测试之前调用,则不会将任何信息附加到报告中。
@AfterTest
public void tearDown() {
extent.flush();
推荐阅读
- python - python3 pip 无法在 Windows 10 上安装 jupyter
- java - IntelliJ IDEA 2019 运行 Java 11(在构建 Gradle 项目时)即使每个选项都设置为 Java 8?
- r - 我有一个矩阵形式的联合 PMF。如何使用 R 找到 $P(N > G)$?
- string - 在 kotlin 中解析“value=1234; some other things”会更紧凑/更简洁
- javascript - 量角器测试 - 失败:javascript 错误:[$injector:modulerr]
- node.js - NodeJs - API 中的 Mongoose 查询仅在 Mocha Chai 测试中失败
- python-3.x - peewee,如何查询指定的表?
- go - 使用 golang 和并发验证 9x9 数独板
- r - R中的强制网络图
- opengl - 现代Opengl:旋转一个长方体,在长方体的一端有枢轴