Hello Revathi, to pass parameter through testng.xml file to a test case, we can 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 and add a test method say parameterizedTest() to the test class. This method takes a string as input parameter. Add the annotation @Parameters(“browser”) to this method.
public class ParameterizedTest {
@Test
@Parameters("browser")
public void parameterizedTest(String browser){
if(browser.equals("firefox")){
System.out.println("Open Firefox Driver");
}else if(browser.equals("chrome")){
System.out.println("Open Chrome Driver");
}
}
}
We could set the parameter using the below syntax in the testng.xml file:
<parameter name="browser" value="firefox"/>
Here, name attribute represents the parameter name and value represents the value of that parameter.