gpt4 book ai didi

java - ExtentReports - 屏幕截图不在报告中 - 损坏的图像

转载 作者:塔克拉玛干 更新时间:2023-11-01 23:02:09 24 4
gpt4 key购买 nike

我正在尝试将屏幕截图添加到我的 ExtentReport HTML 文件中,但由于某种原因,图像不存在,即使它确实存在并且控制台显示它正在查看正确的位置(href 是正确的)。

这是最新的试用代码:

Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);
String destination = getScreenshotPath();
ImageIO.write(screenshot.getImage(), "IMG", new File(destination));
test.fail("Details: " + test.addScreenCaptureFromPath(destination));

屏幕截图保存在目的地。当我尝试 Debug模式或查看报告时,它打印为:

详情:com.aventstack.extentreports.ExtentTest@62041567它下面有一张破损的图片:

enter image description here

最佳答案

我用的是绝对路径

注意:从浏览器检查损坏的图像以验证图像的绝对路径

截图:

  public static String TakesScreenshot(IWebDriver driver, string FileName)
{

string pathProject = AppDomain.CurrentDomain.BaseDirectory;
string pathScreen = pathProject.Replace("\\bin\\Debug", "");
string path = pathScreen + "project/Test-output/Images/";

StringBuilder TimeAndDate = new StringBuilder(DateTime.Now.ToString());
TimeAndDate.Replace("/", "_");
TimeAndDate.Replace(":", "_");
TimeAndDate.Replace(" ", "_");

string imageName = FileName + TimeAndDate.ToString();

((ITakesScreenshot)driver).GetScreenshot().SaveAsFile(path + "_" + imageName + "." + System.Drawing.Imaging.ImageFormat.Jpeg);

return path + "_" + imageName + "." + "jpeg";
}

使用预览方法的路径将图像附加到报告中:具体步骤中:

ExtentTest.Fail("message", MediaEntityBuilder.CreateScreenCaptureFromPath(TakeScreenShot.TakesScreenshot(driver, "Fatal")).Build());

使用方法"TakesScreenshot"截屏

版本 ExtentReport:3,C#,N单元3

使用 JAVA:

        <dependency>
<groupId>com.relevantcodes</groupId>
<artifactId>extentreports</artifactId>
<version>2.41.2</version>
</dependency>

是:

 ExtentTestManager.getTest().log(LogStatus.ERROR, ExtentTestManager.getTest().addScreenCapture("//ABOLUTE/PATH/IMAGE.PNG"));

问候。

关于java - ExtentReports - 屏幕截图不在报告中 - 损坏的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47555567/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com