Creating configuration properties for Selenium Test Suite

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\\");



Comments 3

  • Appreciate your knowledge sharing. Not many people do this!

  • 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?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.