Parameterization Using TestNG.xml:


  • Sometimes it may be time for us to pass the values of test methods during run time.
  • Parameterization using the testng.xml file will allow users to pass parameters to test methods as an argument using XML file.
  • To test the parameters, use the @Parameters annotation in the code and parameters tag in the XML file to pass parameter values.
  • Runtime can pass some simple values like strings for test methods, you can use this approach to send parameter values through TestNG xml configuration files.
  • For this, you need to use parameter annotations in the code and parameter tags in the XML file to test ways to test parameter values.


There are two types of parameterization in TestNG:

  1. Using Parameters annotation and TestNG XML file.
  2. Using @DataProvider annotation.


Example: Parameterization Using TestNG.xml file:

  • This example we pass parameters using @Parameters annotation.
  • Pass values this parameter using TestNG.xml file.
  • This example we pass parameters using @Parameters annotation.NG.xml file into @Parameters annotation.



Example: Pass parameter values using TestNG.xml file:

  • Provide parameter values into TestNG.xml file to use in TestNG program.
  • Using this syntax we provide values : <parameter name=”user” value=”username”/>.
  • These parameter’s we use in any class.



  • The XML file above has three tests and explains the different methods of passing the parameters of each test methods.
  • The parameter is declared by the parameter tag and name attribute, defines the name of the attribute and it must match the @Parameters annotation attribute in the code.
  • And the value defines the value of the attribute parameter.
  • The parameter tag can also be used at the level of the suite along with the test level.