java - 范围报告 : Not able to see the screenshots on other machine

标签 java selenium webdriver extent

我可以在本地计算机上生成带有屏幕截图的范围报告。 但是,当我将报告邮寄给其他人,或在不同的计算机上打开 html 时,屏幕截图不可见。它说路径无效。

在附加屏幕截图时,我给出了本地计算机的路径。它也在其他机器上搜索相同的路径。 我也尝试将 html 和图片压缩到一个文件夹中。

请帮助我如何将屏幕截图附加到 html 文件中,而无需本地计算机依赖。

最佳答案

您可以通过对获得的屏幕截图进行 Base64 转换来完成此操作。 在您的框架中使用以下代码并尝试一下。

public static String addScreenshot() {
    File scrFile = ((TakesScreenshot) BasePage.driver).getScreenshotAs(OutputType.FILE);
    String encodedBase64 = null;
    FileInputStream fileInputStreamReader = null;
    try {
        fileInputStreamReader = new FileInputStream(scrFile);
        byte[] bytes = new byte[(int)scrFile.length()];
        fileInputStreamReader.read(bytes);
        encodedBase64 = new String(Base64.encodeBase64(bytes));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "data:image/png;base64,"+encodedBase64;
}

关于java - 范围报告 : Not able to see the screenshots on other machine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43062006/

相关文章:

java - 在数组中搜索标记并找到它们

java - 按时停止 while 函数

python - Selenium Chrome Webdriver 获取默认适配器失败错误

c# - 如何使用 selenium 和 c# 将可重复部分添加到页面对象模型?

java - 如何使用 kryonet 客户端处理游戏对象更新

java - 刚开始学习Java。为什么 main() 在一个类里面?

selenium - 在 :all hook 之前带有 rspec 的 capybara / Selenium

java - diver.findElements 在 Selenium 中被挂起

selenium - 动态在 FindsBy 中与 selenium 一起使用

selenium - Chrome : fake microphone input for test purpose