I'm getting null pointer exception for driver
object.
Here is the flow:
BaseClass
initializes thedriver
(WebDriver driver = new ChromeDriver();
)- 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 - Then I create a utility class.
- There is if I am using
navigate
it is giving me null pointer exception thoughutil
class also extendsBaseClass
, becauseUtil
also uses methods present inBaseClass
.
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 Classes but not in Util Classes. It is giving driver = null
public void navigate(String url) {
driver.get(url);
logger("Navigating to " + url);
}