top of page

Welcome
to NumpyNinja Blogs

NumpyNinja: Blogs. Demystifying Tech,

One Blog at a Time.
Millions of views. 

Use and Purpose of ConfigReader and config.properties File in Selenium Framework

May 27, 2025
2 min read

In a robust Selenium framework, maintaining flexibility and scalability is key. One way to achieve this is by using a configuration management approach. In this blog, we’ll explore the use and purpose of the config.properties file and the ConfigReader utility class — two fundamental tools for managing configuration settings in Selenium automation.



The config.properties file is a simple key-value pair text file used to store configuration data such as URLs, browser types, timeouts, credentials, and more. Instead of hardcoding values in your test scripts, you externalize them in this file for better flexibility and reusability.



Purpose

Explanation

Centralized configuration

Stores all settings in one place to avoid hardcoding in the code.

 Easy maintenance

You can update settings like URLs, browser types, timeouts without touching code.

 Environment management

Easily switch between environments (e.g., QA, Staging, Production).

 Test customization

Control test execution dynamically (e.g., choose browser or wait time).


 How to Create a config.properties File


  1. In your Maven project, navigate to:

    • src/test/resources

2. Right-click the folder → New > Folder → Name it: configuration






  1. Inside the configuration folder:

    Right-click → New > File

  2. Name it: config.properties

  3. Click Finish



Your config.properties file is now ready to use!


Sample config.properties file:


Once saved, this file will be used by your test framework to fetch required configurations.


What is ConfigReader?


ConfigReader is a Java utility class designed to read values from the config.properties file. It uses Java’s built-in Properties class to load and provide easy access to configuration data throughout your framework.


Purpose of ConfigReader

Purpose

 Explanation

Reads Config Data from File

Loads the .properties file into memory using Java's Properties class.

Reusable Access Methods

Allows retrieval using methods like getProperty("key").

Avoids Hardcoding

Eliminates duplication and makes test scripts cleaner and more maintainable.

One-Time Initialization

Loads the file only once, improving efficiency and performance.





How to Use in Test Code:


In Your Test Code you need to call your ConfigReader as below:


String browser = ConfigReader.getProperty("browser");

String Url = ConfigReader.getProperty("url");

WebDriver driver = new ChromeDriver();

driver.get(Url);


With this setup, your test code remains clean and fully data-driven.


Summary

File

 Purpose

Stores external configuration like browser, URL, credentials, etc.

Java class that reads values from the properties file and makes them accessible


By externalizing configuration and using a ConfigReader, your Selenium framework becomes cleaner, more maintainable, and adaptable to different test environments.


 
 

+1 (302) 200-8320

NumPy_Ninja_Logo (1).png

Numpy Ninja Inc. 8 The Grn Ste A Dover, DE 19901

© Copyright 2025 by Numpy Ninja Inc.

  • Twitter
  • LinkedIn
bottom of page