[英]Thumbnail of image appears but no image shows after taking screenshot of failed test case in extent reports
Code: 码:
public void tearDown(ITestResult result)
if(result.getStatus()==ITestResult.FAILURE)
String screenshot_path= Utility.captureScreenshot(driver, result.getName());
String image= logger.addScreenCapture(screenshot_path);
logger.log(LogStatus.FAIL, "Title verification", image);
report.endTest(logger);
report.flush();
Utility class function: 实用程序类功能:
public static String captureScreenshot(WebDriver driver,String screenshotName)
try
TakesScreenshot ts=(TakesScreenshot)driver;
File source=ts.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(source, new File("./Screenshots/"+screenshotName+".png"));
System.out.println("Screenshot taken");
catch (Exception e)
System.out.println("Exception while taking screenshot "+e.getMessage());
return screenshotName;
Thumbnail of image appears but no image shows after taking screenshot of failed test case in extent reports 在范围报告中拍摄失败的测试用例的屏幕快照后,出现图像的缩略图,但没有图像显示
尝试:
logger.fail("Title verification",MediaEntityBuilder.createScreenCaptureFromPath("Your image path").build());
Your screenshot is failing because your captureScreenShot method returns the EXACT passed value of result.getname() instead of the desired "./Screenshots/"+screenshotName+".png" 您的屏幕截图失败,因为您的captureScreenShot方法返回了result.getname()的精确传递值,而不是所需的“ ./Screenshots/"+screenshotName+".png”
If you print out the returned value, I think you'll find that's what's happening. 如果您打印出返回值,我想您会发现正在发生的事情。
Alter your code as below: 更改您的代码,如下所示:
String screenShotPath = "./Screenshots/"+screenshotName+".png";
FileUtils.copyFile(source, new File(screenShotPath));
...
return screenShotPath;
在Chrome / Firefox上进行之前的检查,我有类似的东西,您需要将屏幕快照与报告保存在同一文件夹中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.