Hope you all are doing well.
I need assistance in resolving a null pointer issue while developing a new Selenium framework for my company. The problem arises after calling the method "StartBrowser()" from the base class in the browser class. Everything runs smoothly until "StartBrowser()", but then a null pointer exception is thrown.
Thank you in advance for your help.
{
public WebDriver driver;
public WebDriver StartBrowser() throws IOException
{
Properties prop=new Properties();
FileInputStream fis=new FileInputStream(System.getProperty("user.dir")+"\\src\\main\\java\\config\\config.properties");
prop.load(fis);
String browserName=prop.getProperty("browser");
String LADSurl=prop.getProperty("LADSurl");
String GADSurl=prop.getProperty("GADSurl");
String chromeDriverPath=prop.getProperty("ChromeDriverPath");
System.out.println(browserName);
if (browserName.equalsIgnoreCase("chrome"))
{
System.setProperty("webdriver.chrome.driver", chromeDriverPath);
driver=new ChromeDriver();
}
else if(browserName.equalsIgnoreCase("firefox"))
{
}
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().window().maximize();
return driver;
}
}
public class Base {
public static WebDriver driver;
BrowserFactory browser;
public static Properties prop;
public static String LADSurl;
public static String GADSurl;
enter code here
public static void setupPropertiesFile() throws IOException {
Properties prop = new Properties();
FileInputStream fis = new FileInputStream(
System.getProperty("user.dir") + "\\src\\main\\java\\config\\config.properties");
prop.load(fis);
String browserName = prop.getProperty("browser");
String LADSurl = prop.getProperty("LADSurl");
String GADSurl = prop.getProperty("GADSurl");
String chromeDriverPath = prop.getProperty("ChromeDriverPath");
}
public static void OpenApplication(String environment) throws IOException {
BrowserFactory browser=new BrowserFactory();
browser.StartBrowser();
if (environment.equalsIgnoreCase("LADS")) {
driver.get("www.google.com"); // Local ADS URL
} else if (environment.equalsIgnoreCase("GADS")) {
driver.get(GADSurl); // Global ADS URL
}
}
Console error: Jul 26, 2020 1:49:05 PM cucumber.api.cli.Main run WARNING: You are using deprecated Main class. Please use io.cucumber.core.cli.Main
Scenario: Create Student # src/test/resources/Features/CreateUsers.feature:3 chrome Starting ChromeDriver 84.0.4147.30 (48b3e868b4cc0aa7e8149519690b6f6949e110a8-refs/branch-heads/4147@{#310}) on port 47410 Only local connections are allowed. Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe. ChromeDriver was started successfully. Jul 26, 2020 1:49:09 PM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Detected dialect: W3C Given User is on New User page # stepDefinitions.CreateUserSteps.user_is_on_new_user_page() java.lang.NullPointerException at utils.Base.OpenApplication(Base.java:39) at stepDefinitions.CreateUserSteps.user_is_on_new_user_page(CreateUserSteps.java:38) at ✽.User is on New User page(file:///C:/Users/rgorilla/eclipse-workspace/ESA/src/test/resources/Features/CreateUsers.feature:4)
When User provide student information click Save User # stepDefinitions.CreateUserSteps.user_provide_student_information_click_save_user() Then Validate user is created successfully # stepDefinitions.CreateUserSteps.validate_user_is_created_successfully()