TestNG Parameterization Using XML | TestNG Tutorial

TestNG Parameterization Using XML:

Parameterized tests allow developers to run the same test over and over again using different values.

There are two ways to set these parameters:

  • with testng.xml
  • with Data Providers

Let’s see passing parameters with testng.xml:

With this technique, we could define the parameters in the testng.xml file and then reference those parameters in the source files.

Create a java test class, say, ParameterizedTest.java

Add test method parameterizedTest() to your test class. This method takes a string as input parameter

Add the annotation @Parameters(“browser”) to this method. The parameter would be passed a value from testng.xml, which we will see in the next step.

Check below video to see “TestNG Parameterization using XML”

Please be patient. The video will load in some time.

If you liked this video, then please subscribe to our YouTube Channel for more video tutorials.


Here, name attribute represents the parameter name and value represents the value of that parameter. We could use this parameter to the test method parameterizedTest by using @Parameters(“browser”) as mentioned in the above step.

Now let’s see the complete testng.xml file

Console Output:

TestNG will automatically try to convert the value specified in testng.xml to the type of your parameter. Here are the types supported:

  • String
  • int/Integer
  • boolean/Boolean
  • byte/Byte
  • char/Character
  • double/Double
  • float/Float
  • long/Long
  • short/Short

You could find the complete TestNG tutorial here.

TestNG Complete Tutorial

If you are not regular reader of my blog then I highly recommend you to signup for the free email newsletter using the below link.

TestNG Parameterization

Rajkumar SM is a founder of SoftwareTestingMaterial. He is a certified Software Test Engineer by profession and blogger & youtuber by choice. He has an extensive experience in the field of Software Testing. He writes here about Software Testing which includes both Manual and Automation Testing. He loves to be with his wife and cute little kid 'Freedom'.

Leave a Comment

Share via
Copy link
Powered by Social Snap