Skip to main content
added 443 characters in body
Source Link
PDHide
  • 11.1k
  • 2
  • 16
  • 43

You are creatingWhen you declare an object in java the default value it gets is null.

So you declared a newclass variable driver and hence it gets the value null.

Now in your @test so thatthe googletitle method you declared another object driver . So this driver becomes local variable to Google titleto that method and what ever you will have scope local. The class variable driver will still be empty

And in tear down you are accessing the class variable which is still null. That's why you are getting null point exception.

So change

WebDriver driver = new ChromeDriver();

To

driver = new ChromeDriver();

This ensures you are using class variable driver inside the @test method

You are creating a new driver in your @test so that becomes local variable to Google title method.

So change

WebDriver driver = new ChromeDriver();

To

driver = new ChromeDriver();

When you declare an object in java the default value it gets is null.

So you declared a class variable driver and hence it gets the value null.

Now in the googletitle method you declared another object driver . So this driver becomes local to that method and what ever you will have scope local. The class variable driver will still be empty

And in tear down you are accessing the class variable which is still null. That's why you are getting null point exception.

So change

WebDriver driver = new ChromeDriver();

To

driver = new ChromeDriver();

This ensures you are using class variable driver inside the @test method

Source Link
PDHide
  • 11.1k
  • 2
  • 16
  • 43

You are creating a new driver in your @test so that becomes local variable to Google title method.

So change

WebDriver driver = new ChromeDriver();

To

driver = new ChromeDriver();