junit - None of the browsers are able to be launched and getting java.lang.NullPointerException and process exit with -1 -
this hook class.
public class hooks { public string browser; public static webdriver driver; //ie, chrome, opera working ||| firefox ~working @before public void beforeeach() throws ioexception { browser = system.getenv("browser"); if (browser == null) { browser = "ie"; } system.out.println("browser selected " + browser); if (browser.equalsignorecase("chrome")) { desiredcapabilities cap = new desiredcapabilities(); cap.setjavascriptenabled(true); cap.setcapability(capabilitytype.accept_ssl_certs, true); system.setproperty("webdriver.chrome.driver", "c:/program files/seleniumdrivers/chromedriver.exe"); driver = new chromedriver(cap); } else if (browser.equalsignorecase("ie")) { file file = new file("c:/program files/seleniumdrivers/iedriverserver.exe"); system.setproperty("webdriver.ie.driver", file.getabsolutepath()); driver = new internetexplorerdriver(); } else if (browser.equalsignorecase("opera")) { desiredcapabilities capabilities = desiredcapabilities.opera(); capabilities.setcapability(capabilitytype.accept_ssl_certs, true); file file = new file("c:/program files/seleniumdrivers/operadriver.exe"); system.setproperty("webdriver.opera.driver", file.getabsolutepath()); driver = new operadriver(capabilities); } else{ driver = new firefoxdriver(); } driver.manage().timeouts().pageloadtimeout(120, timeunit.seconds); driver.manage().timeouts().implicitlywait(60, timeunit.seconds); driver.manage().window().maximize(); driver.manage().deleteallcookies(); } @after public void close() { driver.quit(); } } i using selenium junit cucumber. have implemented code ie, firefox, chrome, opera. unable launch browsers , getting java null pointer exception. , no other error information in console.
the below java class login steps. clue please?
public class loginsteps { public webdriver driverlaunch; public string landingurl = "https://www.periscopix.com"; public loginsteps() { driverlaunch = hooks.driver; } @given("^i on company landing page$") public void i_am_on_company_landing_page() throws throwable { driverlaunch.navigate().to("https://www.google.com"); driverlaunch.close(); } @given("^i wait time$") public void i_wait_for_some_time() throws throwable { thread.sleep(1000); } @when("^then page loads succesfully$") public void then_the_page_loads_succesfully() throws throwable { assertequals(driverlaunch.getcurrenturl(), landingurl); } } thanks in advance
extend ^hooks^ in ^loginsteps^ , use static driver instance of ^hooks^. remove ^driverlaunch^ variable.
Comments
Post a Comment