Selenium Data Driven Testing

Selenium Data Driven Testing, Read Test Data from an external file (excel/text), Create Selenium Test case and connect Test data to the Test case.

Selenium Data-Driven Testing

Write Selenium Data-Driven Test Case, Inspect HTML Elements, Identify unique locators for Web elements, and perform actions on the web elements using Selenium Webdriver methods.

Prerequisites for Writing Selenium Test Cases, Manual Test Case, Element Locator for locating elements in web pages, Selenium WebDriver API commands for performing actions on the AUT, and programming features for enhancing Selenium test cases.

What is Data-Driven Testing?, Why Data-Driven Testing, How to conduct data-driven testing, and Writing Selenium Data-Driven Test cases.

What is Data-Driven Testing?
Data-driven testing is for conducting Positive and Negative Testing.

Why Data-Driven Testing?
Data-driven testing is for conducting Positive and Negative Testing.

Difference between Parameterization and Data-Driven Testing?
For passing a single value or multiple values we use Parameterization, we use multiple values only for Data-driven testing.

How to conduct Data-Driven Testing?
By using any resource (Test Data file) we can conduct Data-driven testing.

Steps for Data-Driven Testing:
1. Read Test Data from an external file
2. Create a Test case
3. Connect Test data with the Test case

Manual Test Case:

Test Case Name: Data-Driven Testing for admin login functionality by reading test data from a text file

Test Steps:

1. Launch Browser
2. Navigate to gcrShop application Admin interface home page
3. Enter Username
4. Enter Password
5. Click OK Button

Verification Point:
Capture the current URL after click on the Login Button, and compare it with expected.

Input/Test data:
Ref: input.txt

Selenium Data-Driven Test Case

System.setProperty(“”, “C:\\Users\\user\\Downloads\\chromedriver.exe”);

FileReader fileObject = new FileReader(“C:\\Users\\user\\Desktop\\input.txt”);
BufferedReader br = new BufferedReader(fileObject);
String line;
int lineCount=0;
int Iteration=0;

while ((line = br.readLine()) !=null) {
String inputData [] = line.split(“, “, 2);

if (lineCount>1) {

WebDriver driver = new ChromeDriver();

String url= driver.getCurrentUrl();

if (url.equals(“”)) {
System.out.println(Iteration + ” Admin Login is Successful – Passed”);
else {
System.out.println(Iteration+” Admin Login is Unsuccessful – Failed”);


Data-Driven Testing using TestNG

Read Test Data (String type data) from an excel file and conduct Data-Driven testing for Admin Login Functionality

Test Steps:
1. Launch Browser
2. Navigate to gcrShop Admin interface (
3. Enter “Username”
4. Enter “Password”
5. Click “Login” Button

Expected URL/Result:

Verification Point:
Capture the URL after click Login and compare with expected result

Input / Test Data:
Ref: input.xls

Selenium WebDriver Test:

public class DataDriven {
static WebDriver driver;

@Test (dataProvider =”testdata”)
public void adminLogin(String User, String Pwd) throws InterruptedException{
System.setProperty(“”, “E:/chromedriver.exe”);
driver = new ChromeDriver();

String url = driver.getCurrentUrl();

/if (url.contains(“”)){ System.out.println(“Admin Login is Successful – Passed”); } else { System.out.println(“Admin Login is Unsuccessful – Failed”); }/
Assert.assertEquals(url, “”);

public void closeBrowser(){

@DataProvider (name = “testdata”)
public Object[][]readExcel()throws BiffException, IOException {
File f = new File (“C:\Users\admin\Desktop\input.xls”);
Workbook w = Workbook.getWorkbook(f);
Sheet s= w.getSheet(0);
int columns = s.getColumns();
int rows = s.getRows();

String inputData [] [] = new String [rows][columns];

for (int i=0; i<rows; i++){
for (int j=0; j<columns; j++){
Cell c= s.getCell(j,i);
return inputData;

Manual Testing Tutorial

Java Tutorial

Python Tutorial

SQL Tutorial

Selenium, Java, and Testing Videos

Follow me on social media: