Reputation: 11
I am running my selenium tests via Jenkins on Headless Firefox browser on Cent OS. I have written a code to capture screenshots on failure which works absolutley fine on my local windows environment but when I run the same script using Jenkins on CentOS the screenshot captured is of 0 bytes
Below is the Java code to capture Screenshot:
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) {}
}
}
The Screenshots are captured on Test Failure:
@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.sstatic.net/NBNUD.png
[2]: https://i.sstatic.net/qMxPq.png
Upvotes: 0
Views: 563
Reputation: 17
Hi Sometimes there may be permission issue with jenkins , try giving chmod -R 777 * and also try using chown the folder which download , first try manually and try using jenkins you will know the issue easily.
Upvotes: 0