0
I created a class "Messages" and put the Method public Properties getProp() inside it, because I want to access the file config.properties from any other class of my project.
/**
* @author Alang
* Criado em 18/05/2017
*/
package com.pub.Utilities;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
public class Messages {
public Properties getProp() throws IOException
{
Properties props = new Properties();
FileInputStream file = new FileInputStream("../PubProject/properties/config.properties");
props.load(file);
return props;
}
}
The problem that is occurring is that I don’t know how to do this. So as I’ve tried several ways always gives a different error.
For example I created another class called: public class Utilities {...} and within this class I have several methods.
How can I load the parameter value Config.strBrowserType that’s in the file config.properties, within this method getTitle() that is part of the class Utilities?
Here is my Utilities class with just the method getTitle(String strTestStep).
package com.pub.Utilities;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
/**
* @author Alang
*
*/
public class Utilities {
//*** INSTACES *****************************
Properties prop = getProp();
//*** VARIABLES *****************************
private WebDriver wd;
public void getBrowserTitle(String strTestStep){
String strExpectedTitle = prop.getProperty("Config.strBrowserType");
String strActualTitle = wd.getTitle();
if (strExpectedTitle.equals(strActualTitle){
System.out.println(strTestStep + " - PASSED: Application was loaded according expected");
}else{
System.out.println(strTestStep + " - FAILED: Application wasn't loaded according expected");
}
}
}
How can I solve this problem?
You cannot access the method anywhere or cannot read the file configuration ?
– Erick Maia
I can read the contents of the file, I can’t access the method from another class. I wanted the getProp method that lies within the Messages class below to be accessible in any other class. public class Messages { public Properties getProp() throws Ioexception { Properties props = new Properties(); Fileinputstream file = new Fileinputstream("./Pubproject/properties/config.properties"); props.load(file); turn props; } } .
– Alan Goncalves