Google News
logo
Selenium - Interview Questions
What is parameterization in TestNG? How to pass parameters using testng.xml?
Parameterization is the technique of defining values in testng.xml file and sending them as parameters to the test class. This technique is especially useful when we need to pass multiple login credentials of various test environments. Take a look at the code below, in which “myName” is annotated as a parameter.
public class ParameterizedTest1{
 @Test
 @Parameters("myName")
 public void parameterTest(String myName) {
 System.out.println("Parameterized value is : " + myName);
 }
}
 
To pass parameters using testng.xml file, we need to use ‘parameters’ tag. Look at the below code for example :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
 <suite name=&rdquo;CustomSuite">
  <test name=&rdquo;CustomTest&rdquo;> 
   <parameter name="myName" value=&rdquo;John"/>
    <classes>
     <class name="ParameterizedTest1" />
    </classes> 
  </test>
</suite>
Advertisement