Saturday, 6 October 2012

Selenium - Create CONFIG file and read it (java)

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
static Properties CONFIG = new Properties();
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.

1 comment:

  1. Best place to learn Appium Android IOS Automation Testing Training in Chennai
    Go for Appium training in chennai for real time mobile automation testing training with real time project support.
    UI Automation Tools with real time scenarios You can contact 8122241286 for Best APPIUM and selenium Training in Chennai

    ReplyDelete