Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在报告测试中附加屏幕截图_Java_Selenium_Testng_Reportng - Fatal编程技术网

Java 如何在报告测试中附加屏幕截图

Java 如何在报告测试中附加屏幕截图,java,selenium,testng,reportng,Java,Selenium,Testng,Reportng,我需要一些帮助附加一个在报告失败测试用例的屏幕截图。 有人能解释一下这到底是怎么做到的吗。我不熟悉Selenium和Java。 我使用Maven作为构建工具。一旦截图并存储在某个位置,就可以将其作为链接插入测试报告中,因为testng报告是一个html文档 Reporter.log("<a href=" + URL+ ">click to open screenshot</a>"); Reporter.log(“”); URL-本地或网络驱动器上的位置设置此系统属性,

我需要一些帮助附加一个在报告失败测试用例的屏幕截图。 有人能解释一下这到底是怎么做到的吗。我不熟悉Selenium和Java。
我使用Maven作为构建工具。

一旦截图并存储在某个位置,就可以将其作为链接插入测试报告中,因为testng报告是一个html文档

Reporter.log("<a href=" + URL+ ">click to open screenshot</a>");
Reporter.log(“”);

URL-本地或网络驱动器上的位置设置此系统属性,您将能够在报告中创建链接

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>");

          {
public void screenscapture()引发IOException异常{
System.setProperty(“org.uncommons.reportng.escape output”、“false”);
文件scrFile=((TakesScreenshot)driver.getScreenshotAs(OutputType.File);
String Path=“E:\\Automation\\testproject\\Screenshots\\”;
文件screenshotName=新文件(路径+驱动程序.getTitle()+“.png”);
//现在通过复制文件将屏幕截图添加到结果中
copyFile(scrFile,screenshotName);
Reporter.log(“

”); 记录者。日志(“”); {
然后我的记者显示:不是一个可点击的链接。你知道是什么原因吗?当我给出项目的相对路径时,屏幕截图没有附加,比如“././screenshots/screenshot1.jpg”。此外,也没有到图像的链接