java - how to create custom reports in testng -
i have following java code:
public class login { string login_status = null; string login_message = null; @test @parameters({"username","password"}) public void execute(string username, string password) throws ioexception { try { config.driver.findelement(by.linktext("log in")).click(); config.driver.findelement(by.id("user_login")).sendkeys(username); config.driver.findelement(by.id("user_pass")).sendkeys(password); config.driver.findelement(by.id("wp-submit")).click(); // perform validation here boolean expvalue = config.driver.findelement(by.xpath("//a[@rel='home']")).isdisplayed(); if (expvalue) { login_status = "pass"; login_message="login successfull user:" + username + ",password:" + password + ",\n expected: rtmedia demo site link should present on home page of rtmedia actual: rtmedia link present on home page of rtmedia. details:na"; } } catch(exception generalexception) { login_status = "fail"; login_message = "login unsuccessfull user:" + username + ",password:" + password + ",\n expected: rtmedia demo site link should present on home page of rtmedia actual: rtmedia link not present on home page of rtmedia. details:exception occurred:"+generalexception.getlocalizedmessage(); // file scrfile = ((takesscreenshot) config.driver).getscreenshotas(outputtype.file); // fileutils.copyfile(scrfile, new file("c:\\users\\public\\pictures\\failure.png")); } { assert.asserttrue(login_status.equalsignorecase("pass"), login_message); } } }
i wrote above java code login functionality , want create reports whatever result (pass or fail) , should stored in folder? have no idea generating reports , found reports automatically generated testng when run test gets overwritten, not me. help?
there quite few ways can achieve this
- if you're using xml report can implement ireporter , create listener. have override method called
generatereport(list<xmlsuite> xmlsuites, list<isuite> suites, string outputdirectory)
, can have own logic save output in different folder everytime run test case. - there attribute in testng called
filefragmentationlevel
if set 3 think report not overwritten. it's in xml reporter class - you can create listener extend
testlisteneradapter
, overrideonstart(itestcontext testcontext)
method testoutput folder everytime. don't prefer method.
i prefer #1.
Comments
Post a Comment