【问题标题】:when running selenium tests via jenkins on headless firefox browser the screenshots captured is of 0 bytes在无头 Firefox 浏览器上通过 jenkins 运行 selenium 测试时,捕获的屏幕截图为 0 字节
【发布时间】:2017-04-02 01:37:14
【问题描述】:

我正在 Cent OS 上的 Headless Firefox 浏览器上通过 Jenkins 运行我的 selenium 测试。 我已经编写了一个代码来捕获失败的屏幕截图,这在我的本地 Windows 环境中运行良好,但是当我在 CentOS 上使用 Jenkins 运行相同的脚本时,捕获的屏幕截图为 0 字节

下面是捕获屏幕截图的 Java 代码:

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;

public class Screen_Capture {
    public static void takeDesktopScreenshot(WebDriver driver,String dateFormat,String fileFormat,String screenPath){
        File src=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
        try{
            SimpleDateFormat s=new SimpleDateFormat(dateFormat);
            String d=s.format(new Date());
            FileUtils.copyFile(src, new File(screenPath+d+"."+fileFormat));
        }
        catch (Exception e) {}
    }


}

屏幕截图是在测试失败时捕获的:

@Override
    public void onTestFailure(ITestResult arg0) {
        Screen_Capture.takeDesktopScreenshot(driver,dateFormat,fileFormat,screenPath);
        log.error("Test Case Failed");


    }

The Images saved on Jenkins Workspace is blank(0 bytes)

[Screen File Size is 0 Bytes][1]

Please help me to overcome this issue.

I am also attaching my Build Environment Configuration on Jenkins:
[Build Environment Configuration on Jenkins][2]


  [1]: https://i.stack.imgur.com/NBNUD.png
  [2]: https://i.stack.imgur.com/qMxPq.png

【问题讨论】:

    标签: jenkins selenium-webdriver screenshot xvfb


    【解决方案1】:

    您好 有时 jenkins 可能存在权限问题,尝试输入 chmod -R 777 * 并尝试使用 chown 下载的文件夹,首先手动尝试并尝试使用 jenkins,您将很容易知道问题所在。

    【讨论】:

      猜你喜欢
      • 2018-12-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-03
      • 2017-02-01
      • 2020-10-27
      • 2018-10-04
      • 2015-04-07
      • 2011-10-13
      相关资源
      最近更新 更多