I am using Appium for testing Android App using selenium. I have used a method to take screenshot of the testcases. It is running fine. The Image file is saved with name of the dateformat using SimpleDateFormat. If I change the pattern of the dateformat it shows this error:
java.io.IOException: The filename, directory name, or volume label syntax is incorrect
My current pattern which is working fine is in the code is dd-MMM-yyyy__hh_mm_ssaa and it saves my file name as 13-Jul-2017__01_07_01PM. It is not saved on SD card but at the location of my project.
I want to change name to 13-Jul-2017_01:01:01 PM.
here is my method for screenshot:
public void takeScreenShot() {
String destDir;
DateFormat dateFormat;
// Set folder name to store screenshots.
destDir = "screenshots";
// Capture screenshot.
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
// Set date format to set It as screenshot file name.
dateFormat = new SimpleDateFormat("dd-MMM-yyyy__hh_mm_ssaa");
// Create folder under project with name "screenshots" provided to destDir.
new File(destDir).mkdirs();
// Set file name using current date time.
String destFile = dateFormat.format(new Date()) + ".png";
try {
// Copy paste file at destination folder location
FileUtils.copyFile(scrFile, new File(destDir + "/" + destFile));
} catch (IOException e) {
e.printStackTrace();
}
}
What other patterns I can use?