简体   繁体   English

在范围报告中拍摄失败的测试用例的屏幕快照后,出现图像的缩略图,但没有图像显示

[英]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.

相关问题 显示屏幕截图:范围报告中的无 - Screenshot with display:none in Extent Reports 如果测试用例中的某个步骤失败但测试用例通过,即使测试用例的最终状态通过,范围报告也会显示整个测试用例失败 - If a step fails in a test case but test cases passes , extent report shows whole test case as failed even though final status of test case is passed 扩展报告:日志被追加到报告中的单个测试用例上 - Extent Reports: Logs are Getting Appended on to a Single Test Case in the Report 范围报告仅显示最后一个测试用例结果 - Extent report shows only last test case result 拍摄IE屏幕截图会返回黑色图像 - Taking an IE screenshot returns a black image Selenium 2(网络驱动程序):截屏返回黑色图像 - Selenium 2 (webdriver): Taking a Screenshot returns a black image 在范围报告 4 中为失败的场景添加屏幕截图 - Adding screenshot in extent report 4 for the failed scenarios selenium webdriver 中未生成失败测试用例的屏幕截图 - Screenshot for failed test case is not getting generated in selenium webdriver 为什么在使用 Junit 时,范围报告中会附上空白屏幕截图? - Why blank screenshot are getting attached in the extent reports when using Junit? 在带有范围报告的selenium POM中截取屏幕时出现空指针异常 - Null pointer exception while taking screenshot in selenium POM with extent report
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM