Selenium using Java.io FileUtils.copyFile to dynamic destination file name -
Selenium using Java.io FileUtils.copyFile to dynamic destination file name -
take screenshot , re-create file in local folder using java io (webdriver java)
file screenshot = ((takesscreenshot) driver) .getscreenshotas(outputtype.file); fileutils.copyfile(screenshot, new file("d:\\pic\\report.jpg"));
i phone call method more 1 time, in situation dont want repeat file name "report.jpg" please provide suggestion how can alter file name dynamically
like report1 report2 etc.,
a simple way:
fileutils.copyfile(screenshot, new file("d:\\pic\\report_" + system.currenttimemillis() + ".jpg");
i hope don't screenshot every milliseconds. ;-)
you can improve readability using timestamp.
java.text.simpledateformat sdf = new simpledateformat("yyyymmdd't'hhmmsssss"); string newfilename = "d:\\pic\\report_" + sdf.format(new java.util.date()) + ".jpg"; fileutils.copyfile(screenshot, newfilename);
another solution might utilize static counter in helper class.
private static int count = 0; public static void doscreenshot() { count++; string newfilename = "d:\\pic\\report_" + count + ".jpg"; fileutils.copyfile(screenshot, newfilename); }
java selenium selenium-webdriver
Comments
Post a Comment