0
package base;

import java.util.concurrent.TimeUnit;

public class Page{
    
    public static WebDriver driver;
     
    public Page() {
        if(driver==null) {
          WebDriverManager.chromedriver().setup();
          driver.get("https://www.zoho.com/");
          driver.manage().window().maximize();
          driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        }
    }
}
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • 2
    `driver` is still `null` by the time you are calling `driver.get()`. You need to initialize it to an actual `WebDriver` object. – Dev Yego Jul 19 '20 at 07:07

1 Answers1

0

The driver inside if(driver == null){..} will ofcourse be null and when you are trying to do driver.get("https://www.zoho.com/"); you are getting NPE.

You have forgot to assign to the driver variable.

       if(driver==null) {
          WebDriverManager.chromedriver().setup();
          driver = new ChromeDriver();
          driver.get("https://www.zoho.com/");
          driver.manage().window().maximize();
          driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        }
Abhinaba Chakraborty
  • 3,488
  • 2
  • 16
  • 37