Reputation: 296
By using below script, I am taking only one Screenshot every time, which it overrides on the same screenshot.
What should I do If I want to take different screenshots at some small time of interval?
public void screenShot() throws IOException, InterruptedException
{
File scr=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
File dest= new File("filPath/1.png");
FileUtils.copyFile(scr, dest);
Thread.sleep(3000);
}
Upvotes: 0
Views: 3408
Reputation: 3415
You should add timestamp to your file name, e.g.
public void screenShot() throws IOException, InterruptedException
{
File scr=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
File dest= new File("filPath/screenshot_"+timestamp()+".png");
FileUtils.copyFile(scr, dest);
Thread.sleep(3000);
}
public string timestamp() {
return new SimpleDateFormat("yyyy-MM-dd HH-mm-ss").format(new Date());
}
Upvotes: 2
Reputation: 17534
Just use the current time to name your files, this example names the files after the current minutes and hours values (of course you may use seconds, milliseconds, days, whatever..) :
Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
String directory = "filPath";
String fileName = "snapshot_"+ hour + "_"+ minute +".png";
File dest = new File(directory, fileName);
Upvotes: 2