One of the challenges we face while creating test suite is to put common settings into a file and read it from code as and when neccessary. I did struggle a bit so thought sharing this might help any one who encounters similar problem.
Steps:
1) Create a file say in ur src folder or create a new package config and put a file called config.properties
2) From the file where you want to read create a varaiable like
public
3) Then load the content into it from the file you have created
FileInputStream fn = new
FileInputStream("path to project"+ \\src\\configure\\config.properties);
CONFIG
.load(fn);
4) Put a value into file config.properties which has to be read
ex:
#url
mainsite=http://www.rediff.com
5) To read value from file
CONFIG
.getProperty("mainsite"); Some more system properties can be read from system as well
ex: System.getproperty("user.dir") for project
Wil share a sample code some time later but the above steps should help.
No comments:
Post a Comment