【发布时间】: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