Parameterization to Test Cases



This concept is used as we may need to run a single test case with different kind of data. Login page can be tested against various types of data like Blank, invalid, special characters etc.

If there is no data provider concept, then we may need to write many test cases again and again for every kind of data.

Sample example where I have created data, in future will be creating data in excel sheet.

When we observe the output window after running this,we will see that our test cases ran three times for different kinds of dataas shown in the above picture:

  1. Data provider method may not be in same class, it can be in different class.

  2. If data coming from different classes, then we need to write that class name here in dataProviderClass attribute in the @test annotation as below:

Sample example where I have created data, in future will be creating data in excel sheet.

data provider in selenium

Try doing the below example and perform it for all the 3 test cases and observe every method.

Sample example where I have created data, in future will be creating data in excel sheet.

  • Above program remains same, the only difference is that parameters will be sent through xml.

  • Below given is the “testng.xml” file in which we need to pass the parameter values for the test method.


We can try below example as well where we sent parameters to different groups.

In the following code example:

  • We have 2 groups A & B

  • Each test method is assigned to a group

  • If the value of group is A, a particular data set is returned

  • If the value of group is B, another data set is returned


Below is the xml file format:


  • Parameterization is required to create Data Driven Testing.

  • TestNG support two kinds of parameterization, using @Parameter+TestNG.xml and using @DataProvider

  • In @Parameter+TestNG.xml parameters can be placed in suite level and test level. If the same parameter name is declared in both places; test level parameter will get preference over suit level parameter.

  • Using @Parameter+TestNG.xml only one value can be set at a time, but @DataProvider return an 2 dimensional array of Object.

  • If DataProvider is present in the different class then the class where the test method resides needs to provide the name of the class where DataProvider is mentioned.

  • There are two parameters supported by DataProvider are Method and ITestContext see in above program we have method getDataFromDataprovider,observe parameters.