Creating configuration properties for Selenium Test Suite

by seetaram on June 20, 2011

Create a configuration properties file to store parameters such as log file path, test data path, results path, selenium execution speed, wait period, etc, then make changes to the parameters whenever needed.

Java provides a way to create configuration file for storing configurable parameters of an application.  Selenium Test Suite also needs such a file to keep global configuration settings.

In this post let us try to understand how we can create a “.properties” file and how to access values from the properties file.

Create a file text file (using any text editor such as notepad) (as in the file – view file) and save the file as “

Create classes as in the following code snippets:

package com.selftechy.readdata;

 * Author - Seetaram Hegde

import com.selftechy.library.*;

public class TestRun {
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		config cfg = new config("F:\\Helios-Workspace\\Config\\");




package com.selftechy.library;

 * Author - Seetaram Hegde

import java.util.*;

public class config {
	  String str, key;
	  private String filepath;
	  public config(String filepath){
	  public String ReadProperty(String propkey){
		  String propval="";
			  int check = 0;
			  while(check == 0){
				  check = 1;
				  File cfgfile = new File(filepath);
						  Properties props = new Properties();
						  FileInputStream propin = new FileInputStream(cfgfile);
						  check = 0;
			  catch(IOException e){
		return propval;	  


Save both the classes and then execute the first one ( as Java application.  In the file, TestData & ConfigPath are the keys and “F:\\Helios-Workspace\\TestData & F:\\Helios-Workspace\\Config” are the respective values.  In .properties file we can put comments using “#”.  Any sentence that starts with # will be considered as comment.

To access the values of any properties, use the “key” parameter.  For example, to access the value of “TestData” and “ConfigPath” write the code as follows:

config cfg = new config("F:\\Helios-Workspace\\Config\\");



{ 3 comments… read them below or add one }

sandeep June 13, 2012 at 7:46 am

Appreciate your knowledge sharing. Not many people do this!


Nusha September 11, 2012 at 11:03 am

Hello! I copied and pasted the above codes in Eclipse. I created the .properties file and saved it on my desktop.

I am experiencing the following error when i run the :

Exception in thread “main” java.lang.NullPointerException
at Source)
at com.selftechy.library.config.ReadProperty(
at com.selftechy.readdata.TestRun.main(

Can you help me to sort out this issue?


karan November 15, 2013 at 4:54 pm

Hi Nusha,

I know its been long since you posted this, but did you found out a solution for the error?



Leave a Comment

Previous post:

Next post:

Do you want to get updates on the recent articles written? Please subscribe to RSS feed or Email