Read data from Properties file using Java Selenium webdriver

Read data from Properties file using Java Selenium webdriver,We can easily read properties from object repository file or some other files using object type properties,In this post example you will learn perfect knowledge about Read data from Properties file using Java Selenium.Please Read Selenium WebDriver Tutorial.
Properties files are using in Java programming which is mainly using for configuration data in their project like data base configuration details,GUI Element data etc.In Selenium Test scripting you can use properties files to read the data from files to your Test scripts in order to maintain clean scripts and clear understanding of test scripts.
Read data from Properties file using Java Selenium webdriver
Properties file in Selenium WebDriver

Read data from Properties file using Java Selenium

In below example you will understand how to create properties file and read data from properties files ,please read full article to understand clearly and i have given brief explanation below the end of the code with each step so that you people can understand clearly.Let’s see the below code.

import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class PropertiesFilesSelenium {

 //Read data from Properties file using Java Selenium
 //OR= Object Repository:
 public static WebDriver driver;

 public void openBrowser() throws FileNotFoundException{

 driver = new FirefoxDriver();
 //using properties to create object
 Properties property = new Properties();
 //Call the file OR.propoeties file using FileInputStream
 FileInputStream objFile = new FileInputStream("E:\QTP Tutorials\Selenium Automation\ExtentUsages\");

 //Load the properties File
 try {


 } catch (IOException e) {


 //Open Software Testing blogspot
 //Maximize the window
 driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
 System.out.println("Window is maximized");
 //Click on Manual Testing menu
 driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
 System.out.println("Clicked on Manual Testing menu");
 //Click on QTP Tutorials
 driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
 System.out.println("Clicked on QTP Testing menu");
 //Click on SeleniumTutorials
 driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
 System.out.println("Clicked on sELENIUM Testing menu");
 //Click on LoadrunnerTutorials
 driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
 System.out.println("Clicked on Loadrunner Testing menu");



Once you run above program you will get below output in Eclipse console

ALSO READ  How to send attachments in jenkins emails

Window is maximized
Clicked on Manual Testing menu
Clicked on QTP Testing menu
Clicked on sELENIUM Testing menu
Clicked on Loadrunner Testing menu
PASSED: openBrowser

Default test
Tests run: 1, Failures: 0, Skips: 0

Properties File

#Software Testing Application Object Properties


#Different Menu's Properties

Code Explanation:

Below details will give you brief details about above code in detail explanation,let’s start understanding the code.

ALSO READ  How to capture screenshot for failed test cases in Selenium

Properties property = new Properties();
In Above i have created one object under Properties() because wit this object you can load or read the properties file easily.

FileInputStream objFile = new FileInputStream(“E:\QTP Tutorials\Selenium Automation\ExtentUsages\”);

FileinputStream in java is useful in reading the different files in order to get the data from specified file and here we are going to use this FileInputStream to load the file into our scripts.

ALSO READ  Selenium WebDriver Scripting Guidelines

try {
} catch (IOException e) {

In order to load the FileinputStream file ,you can use above try catch block for load the file in order to avaoid IOException while executing the script.


In order to read the data from Propoerties file just you need to use property.getProperty(String Key),here property is created object in properties i.e property and getProperty is a method to read the properties from property files. Thank you for reading please share my post.

Rajesh K