top of page
  • Writer's picture9to5 Technologies

Data Driven using Properties files in Selenium webdriver

Updated: Dec 9, 2019

Most of the time, we need to test our script in different environment like test, Production and with different login credentials.

To achieve this we need to get the urls and login credentials from a variable data instead of making a whole script customization. Similarly we could have different purpose and tweaks for data driven. Even we can connect the data source using spreadsheets, data connectors etc. Here we have one more option for small data handling.

Here is the step by step Procedure which gives an idea on how to drive login credentials text boxes with different sets of data from a properties file: 1.Create a Java Project in Eclipse. 2.Right click on the Source folder , go to File >> New >> File . 3.Create a new file named 4. Insert following data into it: password=abcd@123

5. Change your code accordingly and Run.


public class datapro { public WebDriver driver;

@BeforeTest public void login() { // TODO Auto-generated method stub

System.setProperty(“”, “D:\\Tools\\BrowserDriver\\chromedriver.exe”); driver=new ChromeDriver();

//implicit wait driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

driver.get(“website url”); // driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS); driver.manage().window().maximize(); System.out.println(driver.getTitle());


@Test public void throughfile() throws IOException{

Properties prop= new Properties();

FileInputStream fis=new FileInputStream(“path of properties file\\src\\”);



driver.findElement(By.xpath(“.//* [@id=’inputEmail’]”)).sendKeys(prop.getProperty(“username”)); driver.findElement(By.xpath(“.//* [@id=’inputPassword’]”)).sendKeys(prop.getProperty(“password”)); driver.findElement(By.xpath(“html/body/form/div/div/div[1]/div/div/button[2]”)).click();



2 views0 comments
bottom of page