java - Capture screenshot -
how take screenshot of failed test case test case name? example: suppose test case name testvelifylogin(). if fails screenshot name should testvelifylogin_time_date.jpg
please me how this.
i have written code screen shot following:
public void ontestfailure(itestresult itestresult) { string path = system.getproperty("user.dir") + "\\testoutput\\screenshots"; dateformat dateformat = new simpledateformat("hh_mm_ss_dd_mm"); calendar cal = calendar.getinstance(); string date = dateformat.format(cal.gettime()); file scrfile = ((takesscreenshot) driver) .getscreenshotas(outputtype.file); try { fileutils.copyfile(scrfile, new file(path,"screenshot_"+date+".jpg")); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } }
instead of screenshot_ want test case name.
you itestresult object. instance,
string testname = itestresult.getname();
Comments
Post a Comment