How to use Properties Files in Selenium Framework

What is Properties?

It is mainly used to store configuration parameters of an application. Each parameter is stored as a pair of strings   i.e. both key and value are of type string.

Advantage of using Properties?

If any value changes in the properties file then we don’t need to recompile the java class

How to use Properties Files with Selenium?

  • It can be used to store all the configuration parameters like environment details, user credentials, database details, etc.… instead of hard coding it in the scripts
  • It can be used as an object repository where we can store all the elements and their identifiers


public class FirstTest {
    public void OpenBrowser()  {
        String driverPath = PropertyFileUtils.loadFrameworkProperties().getProperty("chrome.driver.path");
        String url = PropertyFileUtils.loadApplicationProperties().getProperty("application.url");
        WebDriver driver;
        System.setProperty("", driverPath);
        driver = new ChromeDriver();
        Assert.assertTrue("Page title is not correct",driver.getTitle().equals("Google"));
public class PropertyFileUtils {

    public static Properties loadProperties(String path){
        Properties properties = new Properties();
        FileInputStream file = null;
        try {
            file = new FileInputStream(path);
        } catch (FileNotFoundException e) {
        try {
        } catch (IOException e) {
        return properties;

    public static Properties loadApplicationProperties(){
        Properties properties = loadProperties("src\\test\\resources\\");
        return  properties;

    public static Properties loadFrameworkProperties(){
        Properties properties = loadProperties("src\\test\\resources\\");
        return  properties;





Bijan Patel

Founder & Creator of QAScript | 12+ years of IT Experience | Full Stack Automation Engineer | Blogger | Trainer

You may also like...

Leave a Reply

Your email address will not be published.