You were getting NullpointerException because you are declaring another ChromeDriver instance inside the initialize() method and creating an instance of ChromeDriver object whose scope is limited to initialize() method itself.

Make the following corrections in the code:

In Base class:

public void initialize() {
 ..some code

   = new ChromeDriver() ;

..some code 
}

And you don’t need another WebDriver driver declaration in Front class.( you can remove it).

In Front class:

public class Front extends Base {

  @Test
  public void Login() throws InterruptedException {
      Pages PagesObj = new Pages(driver);
      PagesObj.Googletext();  
  }
}

So, now the driver gets initialized in initialize() method of Base class and the same driver instance is passed through to your Page object.



Source link https://sqa.stackexchange.com/questions/32413/java-lang-nullpointerexception--while--driver-

LEAVE A REPLY

Please enter your comment!
Please enter your name here