What is Data Driven Testing Techniques in Selenium?

Data-driven testing is one of the popular testing approach. Why this approach is so popular and useful?

Take a real life example. Just write the test cases to test the “Username” field for the rediffmail pages.

The possible test-cases at gross level are:-

Test Case IDTest Case SubjectTest Case DescriptionTest StepsPrerequisitesExpected ResultsActual Results
1Username fieldUserName field accepting the alphaneumeric inputsEnter the alphaneumeric inputsUser on the landing pageIt should workTo be tested
2Username fieldUserName field accepting only 10 characters in the text boxEnter the valid inputsUser on the landing pageIt should workTo be tested
3Username fieldUserName field accepting not accepting only numbersEnter the valid inputsUser on the landing pageIt should workTo be tested

So if we want to automate these scenarios, then how to code it ?

The efficient way should be, use the same piece of code but use the different inputs. Rather than writing different piece of code or hard coding the different inputs values. This Technique of testing is called the Data Driven testing techniques. This technique enables us to separate the test data from the test logic.In this techniques , the data can be passed into the code from external source like different class file or from the csv files.

We can apply the Data-Driven testing techniques in the above case because our test subject is constant , that is the “Username” field and we are expecting different test outputs for different input combinations.

Main Benefits of this Data-Driven Techniques:-

  1. Maximum number of test case coverage with minimum code. So it increases the maintainability and readability of automation test scripts.
  2. By using this techniques, we can design our test data inputs prior to application build.

As Selenium Web Driver does not provide any built in features for Data- Driven testing. So we have to use the Frameworks like TestNg to perform it. Or we can use Apache POI API to pull data from excel.

The most common ways to achieve the Data-Driven testing techniques are mentioned below:-