java.lang.NullPointerException: Can’t invoke “org.openqa.selenium.WebDriver.give up()” as a result of “this.driver” is null
at hooks.MyHook.teardown(MyHook.java:24)
public class MyHook extends Base{
@Earlier than
public void beforeScenario(){
System.out.println("Situations has began");
}
@After
public void teardown() {
driver.give up();
}
}
public class Base {
public WebDriver driver;
public Properties prop;
public WebDriver initializeDriver() throws IOException{
prop= new Properties();
FileInputStream fis=new FileInputStream("C:CustomersCITPL-Developer-2eclipse-workspaceFdmssrcimportantjavacitplsourcesknowledge.properties");
prop.load(fis);
String browserName = System.getProperty("browser")!=null ? System.getProperty("browser") :prop.getProperty("browser");
if(browserName.equals("chrome"))
{
ChromeOptions choices = new ChromeOptions();
choices.addArguments("--remote-allow-origins=*");
System.setProperty("webdriver.chrome.driver","C:CustomersCITPL-Developer-2driverchromedriver.exe");
if(browserName.comprises("headless")){
choices.addArguments("headless");
}
driver = new ChromeDriver(choices);
driver.handle().window().maximize();
}
driver.handle().timeouts().implicitlyWait(Length.ofSeconds(10));
return driver;
}
public class LoginSteps extends Base{
@Given ("Naviagate to the login web page")
public void Naviagate_to_the_login_page() throws IOException {
initializeDriver();
driver.get(prop.getProperty("url"));
}
@When ("^I enter legitimate username (.+) and password (.+)$")
public void I_enter_valid_username_valid_username_and_Pasword(String username, String password) throws InterruptedException {
LoginPage lp= new LoginPage(driver);
lp.entervalidCredentials(username, password);
}