在无头firefox浏览器上通过jenkins运行selenium测试时,捕获的屏幕截图为0字节

时间:2016-11-18 09:07:22

标签: jenkins selenium-webdriver screenshot xvfb

我在Cent OS的Headless Firefox浏览器上通过Jenkins运行我的selenium测试。 我编写了一个代码来捕获失败的屏幕截图,这在我的本地Windows环境中运行absolutley,但是当我在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

1 个答案:

答案 0 :(得分:0)

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