Pls help me with this error "java.lang.NullPointerException". Chrome driver is getting initiaze properly but at the time of running test it is giving this error.
In my test class I'm extending setup class which extends driver class.
This way i m using same driver instance in all of my classes. Then why this exception is occurring?
Below is my code
public class GetDriver {
public WebDriver driver;
public WebDriver getD(){
return driver;
}
}
public class util{
public static void launchbrowser(WebDriver driver ){
System.setProperty("webdriver.chrome.driver","path to chromedriver.exe");
driver = new ChromeDriver();
}
public static void login(String user, String password, WebDriver driver) throws Exception{
LoginPage loginpage = PageFactory.initElements(driver, LoginPage.class);
loginpage.loginid(user, password);
loginpage.clicksubmit();
}
}
public class Setup extends GetDriver {
@BeforeClass
public void startTest(){
util.launchbrowser(url, driver);
driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);
}
}
public class login extends Setup {
@Test(priority=0)
public void TestLogin() throws Exception{
String url = "website";
driver.get(url);
util.login("website","password",driver);
boolean bool = driver.findElement(By.xpath("//span[contains(text(),'Your username or password is incorrect')]")).isDisplayed();
assertTrue(!bool,"password incorrect");
}
}