selenium - Null pointer exception when using extent report -
i have 2 classes baseclass
, tescaseloginpage
. when trying execute tescaseloginpage
class without report/logger (extentreport),test case getting pass. when puttin extend report code, getting nullpointerexception
.could please me
i have written report.endtest(logger);
in line no 51. tried comment line , executed. time got same error in line no 50 i.e.
logger.log(logstatus.info,"browser closed");
. every time commenting error line, getting same error in new log related line only.
error log below :
url : http://store.demoqa.com//products-page//your-account// failed configuration: @afterclass close java.lang.nullpointerexception @ testcases.testcaseloginpage.close(testcaseloginpage.java:51) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl(nativemethodaccessorimpl.java:62)
sun.reflect.delegatingmethodaccessorimpl.(delegatingmethodaccessorimpl. java:43) @ java.lang.reflect.method.invoke(method.java:498) @ org.testng.internal.methodinvocationhelper.(methodinvocationhelper.java:104)
at org.testng.internal.invoker.invokeconfigurationmethod(invoker.java:515) @ org.testng.internal.invoker.invokeconfigurations(invoker.java:217) @ org.testng.internal.invoker.invokeconfigurations(invoker.java:144) @ org.testng.internal.invokeafterclassmethods(testmethodworker.java:217) @ org.testng.internal.testmethodworker.run(testmethodworker.java:115) @ org.testng.testrunner.privaterun(testrunner.java:756) @ org.testng.testrunner.run(testrunner.java:610) @ org.testng.suiterunner.runtest(suiterunner.java:387) @ org.testng.suiterunner.runsequentially(suiterunner.java:382) @ org.testng.suiterunner.privaterun(suiterunner.java:340) @ org.testng.suiterunner.run(suiterunner.java:289) @ org.testng.suiterunnerworker.runsuite(suiterunnerworker.java:52) @ org.testng.suiterunnerworker.run(suiterunnerworker.java:86) @ org.testng.testng.runsuitessequentially(testng.java:1293) @ org.testng.testng.runsuiteslocally(testng.java:1218) @ org.testng.testng.runsuites(testng.java:1133) @ org.testng.testng.run(testng.java:1104) @ org.testng.remote.abstractremotetestng.run(abstractremotetestng.java:132) @ org.testng.remote.remotetestng.initandrun(remotetestng.java:236) @ org.testng.remote.remotetestng.main(remotetestng.java:81) failed: login java.lang.nullpointerexception @ testcases.testcaseloginpage.login(testcaseloginpage.java:35) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)
here code :
baseclass.java
package testcases; import org.openqa.selenium.by; import org.openqa.selenium.webdriver; import org.openqa.selenium.support.pagefactory; import org.openqa.selenium.support.ui.expectedconditions; import org.openqa.selenium.support.ui.webdriverwait; import com.relevantcodes.extentreports.extentreports; import com.relevantcodes.extentreports.extenttest; import com.relevantcodes.extentreports.logstatus; import factory.browserfactory; import factory.dataproviderfactory; import pages.loginpage; public class baseclass { webdriver driver; extentreports report; extenttest logger; string logintext; public void setup() { driver=browserfactory.getbrowser("chrome"); driver.get(dataproviderfactory.getconfig().getapplicationurl()); } public void loginintoapplication() { loginpage login=pagefactory.initelements(driver, loginpage.class); login.login(dataproviderfactory.getexcel().getdata(0, 0, 0), dataproviderfactory.getexcel().getdata(0, 0, 1)); } public string loginverification() { try { thread.sleep(5000); } catch (exception e) { system.out.println(e.getmessage()); } //webdriverwait wait=new webdriverwait(driver, 20); //wait.until(expectedconditions.visibilityofelementlocated(by.xpath("//li[@id='wp-admin-bar-my-account']/a"))); logintext=driver.findelement(by.xpath("//li[@id='wp-admin-bar-my-account']/a")).gettext(); logger.log(logstatus.info, "logiin account text has been captured successfully"); return logintext; } public void teardown() { driver.quit(); } }
testcaseloginpage.java
package testcases; import org.openqa.selenium.by; import org.openqa.selenium.support.ui.expectedconditions; import org.openqa.selenium.support.ui.webdriverwait; import org.testng.assert; import org.testng.annotations.aftertest; import org.testng.annotations.beforetest; import org.testng.annotations.test; import com.relevantcodes.extentreports.logstatus; import pages.loginpage; public class testcaseloginpage extends baseclass { //webdriver driver; //baseclass base=pagefactory.initelements(driver, baseclass.class); @beforetest public void initial() { base.setup(); } @test(priority=1) public void login() { base.loginintoapplication(); try { thread.sleep(5000); } catch (exception e) { system.out.println(e.getmessage()); } //webdriverwait wait=new webdriverwait(driver, 20); //wait.until(expectedconditions.visibilityofelementlocated(by.xpath("//a[contains(.,'howdy')]"))); logger.log(logstatus.info, "logiin applicaion successfully"); //loginpage login=pagefactory.initelements(driver, loginpage.class); loginpage login=new loginpage(driver); base.loginverification(); system.out.println("login text : "+base.logintext); assert.assertequals(base.logintext, login.exp,"unable verify login verification"); logger.log(logstatus.pass, "verified login account expected user successfully"); } @aftertest public void close() { base.teardown(); logger.log(logstatus.info, "browser closed"); report.endtest(logger); report.flush(); } }
initialize logger in test.
use line:
logger = extent.createtest("test name","description");
make first line before call logger in test.
for reference see software automata - extent reports in selenium
Comments
Post a Comment