We can pass test data as parameters from testng.xml to the tests directly using TestNG Parameters feature.
To pass any parameter from testng.xml we can define "parameter" tag at suite, test and class level in testng.xml. Syntax is <parameter name="name_of_parameter", value="value_of_parameter"/>. We can add any number of parameters for a test. Please see the below screenshot.
To use the parameters in the test methods, we have to use @Parameters annotation provided by TestNG. And @Parameters annotation can be used with the methods that has @Test, @BeforeXXXX, @AfterXXXX or @Factory annotations. Inside @Parameters annotation we have to give the name of the parameters and these names must be same as what we have given in the testng.xml as shown in the below screenshot.
To pass any parameter from testng.xml we can define "parameter" tag at suite, test and class level in testng.xml. Syntax is <parameter name="name_of_parameter", value="value_of_parameter"/>. We can add any number of parameters for a test. Please see the below screenshot.
To use the parameters in the test methods, we have to use @Parameters annotation provided by TestNG. And @Parameters annotation can be used with the methods that has @Test, @BeforeXXXX, @AfterXXXX or @Factory annotations. Inside @Parameters annotation we have to give the name of the parameters and these names must be same as what we have given in the testng.xml as shown in the below screenshot.