1

Already tried this solution but no luck yet :

Cannot load properties file from resources directory

My Code:

protected WebDriver driver;
public static Properties prop;    

@BeforeSuite
    public void setup()
    {

        ChromeOptions options = new ChromeOptions();
        options.addArguments("--disable-notifications");

        System.setProperty("webdriver.chrome.driver","E:\\chromedriver.exe");
        driver = new ChromeDriver(options);

        //Calling property file function here
        ReadData();

        driver.get(prop.getProperty("URL"));

    }

    public void ReadData()
        {  prop = new Properties();
            try {
                prop.load(new FileInputStream("D:\\projectname\\src\\main\\resources\\DataFile.properties"));
            } catch (IOException e) {
                e.printStackTrace();
            }}

Getting Exception :

java.io.FileNotFoundException

File is already there and I have tried lot of diff. file path like full path, path starts from src ect.

Project Structure :

http://prntscr.com/g1bpq2

UPATE :

  1. It works when I removed .properties extension from filepath.
  2. Still I am not sure that why intellij did not add file extension as .properties. Because I am sure that I have created file with type properties.
Helping Hands
  • 5,292
  • 9
  • 60
  • 127

2 Answers2

2

Here is the Answer to your Question:

Instead of :

prop.load(new FileInputStream("D:\\projectname\\src\\main\\resources\\DataFile.properties"));

Can you try:

prop.load(new FileInputStream("./src/main/resources/DataFile.properties"));

Let me know if this Answers your Question.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
1

You need to use \\ in java to give the absolute path like below :-

D:\\Demo_Login\\src\\main\\resources\\DataFile.properties

You can use File.separator instead of putting \\

OR

you can do something like below :-

        File src=new File("src\\lib\\phantomjs\\phantomjs.exe");

        System.setProperty("phantomjs.binary.path",src.getAbsolutePath());

OR

You can try something like below using . which start directory from project root directory :-

System.setProperty("webdriver.chrome.driver","./src"+File.separator+"lib"+File.separator+"chromedriver.exe")

OR

Start with src like that :-

"src/main/resources/DataFile.properties"

Hope it will help you :)

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125