I created a " Messages
" class and put the public Properties getProp()
method inside it, because I want to access the config.properties
file from any other class in 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 do not know how to do this. So as I've tried several ways it 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 value of the Config.strBrowserType
parameter that is in the config.properties
file, within this getTitle()
method that is part of the Utilities
class?
Here is my Utilities class with only the getTitle(String strTestStep)
method.
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?