0

代码:

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

实用程序类功能:

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; 

在范围报告中截取失败的测试用例后,出现图像缩略图但没有图像显示

4

3 回答 3

0

您的屏幕截图失败,因为您的 captureScreenShot 方法返回了 result.getname() 的确切传递值,而不是所需的 "./Screenshots/"+screenshotName+".png"

如果你打印出返回值,我想你会发现这就是正在发生的事情。

更改您的代码如下:

String screenShotPath = "./Screenshots/"+screenshotName+".png";
FileUtils.copyFile(source, new File(screenShotPath));

...

return screenShotPath;
于 2018-12-10T16:05:00.367 回答
0

之前在 Chrome/Firefox 上检查,我有类似的东西,您需要将屏幕截图与报告保存在同一文件夹中。

于 2018-12-27T14:13:07.263 回答
0

尝试:

logger.fail("Title verification",MediaEntityBuilder.createScreenCaptureFromPath("Your image path").build());
于 2018-12-10T05:11:14.283 回答