java - Issue in the TESTNG program when I use "Priority" tag -
code: program using @test method priority tags.
package testng1; import static org.testng.assert.assertequals; import org.openqa.selenium.webdriver; import org.openqa.selenium.ie.internetexplorerdriver; import org.testng.assert; import org.testng.annotations.test; @test public class testng { public static webdriver driver; public void verifytitle() { system.setproperty("webdriver.ie.driver", "c:\\users\\rprem\\downloads\\iedriverserver_x64_3.4.0\\iedriverserver.exe"); webdriver driver = new internetexplorerdriver(); driver.navigate().to("https://google.com"); string title = driver.gettitle(); system.out.println(title); assert.assertequals(title, "google"); } @test (priority = 1) public void verifytitle2() { driver.get("https://gmail.com"); string titlee = driver.gettitle(); assert.assertequals(titlee, "gmail - free storage , email google"); } }
when run program i'm getting "java null pointer exception" issue. per logic methods executed in alphabetical order, when put priority run in given order. it's not happening that.
error message:
google passed: verifytitle failed: verifytitle2 java.lang.nullpointerexception @ testng1.testng.verifytitle2(testng.java:22) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:498) @ org.testng.internal.methodinvocationhelper.invokemethod(methodinvocationhelper.java:108) @ org.testng.internal.invoker.invokemethod(invoker.java:661) @ org.testng.internal.invoker.invoketestmethod(invoker.java:869) @ org.testng.internal.invoker.invoketestmethods(invoker.java:1193) @ org.testng.internal.testmethodworker.invoketestmethods(testmethodworker.java:126) @ org.testng.internal.testmethodworker.run(testmethodworker.java:109) @ org.testng.testrunner.privaterun(testrunner.java:744) @ org.testng.testrunner.run(testrunner.java:602) @ org.testng.suiterunner.runtest(suiterunner.java:380) @ org.testng.suiterunner.runsequentially(suiterunner.java:375) @ 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:1301) @ org.testng.testng.runsuiteslocally(testng.java:1226) @ org.testng.testng.runsuites(testng.java:1144) @ org.testng.testng.run(testng.java:1115) @ org.testng.remote.abstractremotetestng.run(abstractremotetestng.java:132) @ org.testng.remote.remotetestng.initandrun(remotetestng.java:230) @ org.testng.remote.remotetestng.main(remotetestng.java:76) =============================================== default test tests run: 2, failures: 1, skips: 0 =============================================== =============================================== default suite total tests run: 2, failures: 1, skips: 0 ===============================================
the problem lies in test code.
in method verifytitle()
please change webdriver driver = new internetexplorerdriver();
driver = new internetexplorerdriver();
since assigning internetexplorerdriver
instance local variable in method, shadowing class level webdriver , when verifytitle2()
tries access it, triggers nullpointerexception
to fix problem, suggest extract out webdriver instantiation logic @beforeclass
method.
@beforeclass() public void beforeclass() { system.setproperty("webdriver.ie.driver", "c:\\users\\rprem\\downloads\\iedriverserver_x64_3.4.0\\iedriverserver.exe"); driver = new internetexplorerdriver(); }
Comments
Post a Comment