【发布时间】:2013-12-05 17:55:04
【问题描述】:
我需要一些帮助,附上 ReportNG 中失败测试用例的屏幕截图。 有人可以解释一下这是如何完成的。我是 Selenium 和 Java 的新手。 我使用 Maven 作为构建工具。
【问题讨论】:
标签: java selenium testng reportng
我需要一些帮助,附上 ReportNG 中失败测试用例的屏幕截图。 有人可以解释一下这是如何完成的。我是 Selenium 和 Java 的新手。 我使用 Maven 作为构建工具。
【问题讨论】:
标签: java selenium testng reportng
@Cagy79 设置此系统属性,您将能够在 ReportNG 中创建链接。
System.setProperty("org.uncommons.reportng.escape-output", "false");
【讨论】:
您可以使用下面的脚本并在您需要的每个类中调用该方法。
public void screenCapture() throws IOException{
System.setProperty("org.uncommons.reportng.escape-output", "false");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
String Path = "E:\\Automation\\testproject\\Screenshots\\";
File screenshotName = new File(Path +driver.getTitle()+".png");
//Now add screenshot to results by copying the file
FileUtils.copyFile(scrFile, screenshotName);
Reporter.log("<br> <img src='"+screenshotName+"' height='100' width='100' /><br>");
Reporter.log("<a href="+screenshotName+"></a>");
{
【讨论】:
当您截取屏幕截图并存储在某个位置后,您可以将其作为链接插入到测试报告中,因为 testng 报告是一个 html 文档。
Reporter.log("<a href=" + URL+ ">click to open screenshot</a>");
URL - 本地或网络驱动器上的位置
【讨论】: