I’m getting pointer exception for object.

Here is the flow:

  1. BaseClass initializes the driver ( driver = new ChromeDriver();)
  2. I create a test class and extend it with BaseClass. Now I am able to use all methods present in BaseClass example navigate, openBrowser, click , type, isLogin etc
  3. Then I create a class.
  4. There is if I am using navigate it is giving me null pointer exception though util class also extends BaseClass, because Util also uses methods present in BaseClass.

Flow is for Test Class is:

openBrowser("Chrome"); // driver present
method from BaseClass;driver present
method from BaseClass;driver present
method from BaseClass;driver present
method from util class;driver=null

What am I doing wrong?

Edit:
I checked Thiago Fioravante’s answer here WebDriver instantiation in Selenium framework but didn’t quite get it, what he is saying. However, problem same i.e. I want to use same driver instance across the project.

Edit2:
This navigate method is working in test but not in Util . It is giving driver = null

public void navigate(String url) {
        driver.get(url);
        logger("Navigating to " + url);
    }



Source link https://sqa.stackexchange.com/questions/32207/driver-is-getting-null-for-utility-classes

LEAVE A REPLY

Please enter your comment!
Please enter your name here