webdriver - Facing NullPointerException in Selenium -


i have created 3 files: 1 index file, other configuration file , last last 1 property file. while executing code i'm getting nullpointerexception.

i not able solve issue. please me rectify code.

index.java:

package main; import org.openqa.selenium.webdriver; import org.openqa.selenium.chrome.chromedriver; import org.testng.annotations.test; import config.configuration;  public class index  {     webdriver driver;     @test(priority = 1)     public void handling_multiple_windows() throws exception     {         configuration obj = new configuration();         system.setproperty("webdriver.chrome.driver", obj.path());         driver = new chromedriver();         driver.manage().window().maximize();         driver.get(obj.handling_window_url());     } } 

configuration.java:

package config; import java.io.file; import java.io.fileinputstream; import java.util.properties; import org.openqa.selenium.webdriver;  public class configuration  {     properties pro;     webdriver driver;     public configuration() throws exception     {         file f = new file("./config/config.property");         fileinputstream fis = new fileinputstream(f);         properties pro = new properties();         pro.load(fis);       }         public string path()     {         string url = pro.getproperty("chromedriverpath");         return url;     }      public string handling_window_url()     {         return pro.getproperty("url");     } } 

config.property:

chromedriverpath = g:\\selenium webdriver\\chromedriver\\chromedriver.exe url = https://www.naukri.com 

the reason nullpointerexception because in configuration.java class have declared properties pro; globally again within configuration() constructor have again initiated instance of properties properties pro = new properties();. hence nullpointerexception.

change line:

properties pro = new properties(); 

to:

pro = new properties(); 

your code work fine.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -