Which Annotation Is Used in Testng for Passing Parameters?

You have to use the @Parameters annotation for passing parameter values to the test method. Let's write a simple example of passing parameters to test methods through the XML configuration file.

How do you pass parameters in TestNG annotation?

Passing Parameters with testng. xml
  1. Create a java test class, say, ParameterizedTest1. java.
  2. Add test method parameterTest() to your test class. This method takes a string as input parameter.
  3. Add the annotation @Parameters("myName") to this method. The parameter would be passed a value from testng.

What is parameter annotation in TestNG?

Parameters Annotation in TestNG is a method used to pass values to the test methods as arguments using . xml file. Users may be required to pass the values to the test methods during run time. The @Parameters annotation method can be used in any method having @Test, @Before, @After or @Factory annotation.

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.