【发布时间】:2018-02-26 20:48:43
【问题描述】:
public class ScreenCapture {
PartyBase partybase = new PartyBase() ;
public void getscreenshot(String testname)
{
Date date = new Date() ;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss") ;
File scrFile = ((TakesScreenshot)PartyBase.driver).getScreenshotAs(OutputType.FILE);
//The below method will save the screen shot in d drive with name "screenshot.png"
try {
FileUtils.copyFile(scrFile, new File("BaseApp\\BaseApp\\screenshots\\screenshot_"+testname+"_"+dateFormat.format(date)+".png"));
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("e::::::::::"+e);
}
}
}
我正在从 selenium webdriver 截取屏幕截图,并希望将它们保存在我的项目截图文件夹中,如图所示。我无法这样做,请帮助我在代码中需要进行哪些更改。
【问题讨论】:
-
试试
FileUtils.copyFile(scrFile, new File("screenshots\\screenshot_"+testname+"_"+dateFormat.format(date)+".png"));。并刷新文件夹`
标签: java selenium screenshot