top of page
  • Writer's picture9to5 Technologies

Parameterization/Data driven testing in Selenium TestNG using testng.xml file

Updated: Dec 9, 2019

Data-Driven testing as the name suggests is a test driven by the Data. For ex. You have a user detail form where you need to enter details of multiple users and save them. Here if you have 5 different user data available and you have to write automation cases for these, you may end up writing 5 different automation test cases(one for each user data).

If you apply a Data-Driven approach you will end up with only one test-case, that is filling the form with user data and then submitting it. The test case will get executed based on the data provided to it. In this case it will be 5 and hence the test case will get executed 5 times with different data-set.

The advantage of using a Data-driven approach is that you reduce your effort in writing/maintaing test-cases for your different type of data. In case of additions or deletion of new/old entries , you just have to change the data and not your actual test-case.Let’s use following example:

Below is the example for testng.xml file: <?xml version=”1.0″ encoding=”UTF-8″?>

<suite name=”Simple Suite”>

<test name=”Simple Test”>

<parameter name=”userid” value=”userID” />

<parameter name=”password” value=”abcd” />


<class name=“annotate.datapro” />




Please change your code accordingly:


package Testng_Package;

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.AfterTest;

import org.testng.annotations.BeforeTest;

import org.testng.annotations.DataProvider;

import org.testng.annotations.Test;

public class Sample_Login {

WebDriver driver = new FirefoxDriver();


public void setup() throws Exception {


driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

driver.get(“paste url”);



public void tearDown() throws Exception {





public void LogIn_Test(String Userid, String Password) {

driver.findElement(By.xpath(“ //input[@name=’Userid’]”)).clear();

driver.findElement(By.xpath(“ //input[@name=’Password’]”)).clear();

driver.findElement(By.xpath(“ //input[@name=’Userid’]”)).sendKeys(Userid);

driver.findElement(By.xpath(“ //input[@name=’Password’]”)).sendKeys(Password);

driver.findElement(By.xpath(“ //input[@value=’Login’]”)).click();

String alrt = driver.switchTo().alert().getText(); driver.switchTo().alert().accept(); System.out.println(alrt);



10 views0 comments
bottom of page