selenium 在ubuntu环境下能截图吗?
我在ubuntu环境下布了selenium环境,运行case,错误截图总是全黑的,啥也看不到,咋回事哇?...
我在ubuntu环境下布了selenium环境,运行case,错误截图总是全黑的,啥也看不到,咋回事哇?
展开
1个回答
展开全部
需要编写一个截图类ScreenShot
package com.daanhealth.tnb.util;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
public class ScreenShot {
public WebDriver driver;
public ScreenShot(WebDriver driver){
this.driver=driver;
}
private void takeScreenshot(String screenPath){
try {
File srcFile=((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(srcFile, new File(screenPath));
} catch (Exception e) {
// TODO: handle exception
System.out.println("Screen shot error: " + screenPath);
}
}
public void takeScreenshot(){
String screenName=new DateFormat().formatDateToString(System.currentTimeMillis())+".jpg";
File dir=new File("test-output/snapshot");
if(!dir.exists()){
dir.mkdirs();
}
String screenPath=dir.getAbsolutePath()+File.separator+screenName;
takeScreenshot(screenPath);
}
}
追问
我已经写了截图类,可是还是截图还是有问题,是selenium不支持ubuntu截图吗?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询