Home » TestNG Parameters

TestNG Parameters

by Online Tutorials Library

TestNG Annotation Attributes

TestNG Parameters are the arguments that we pass to the test methods. There are two ways through which we can pass the parameters to the test methods:

  • TestNG Parameters
  • TestNG DataProviders

In this topic, we will learn about the TestNG Parameters. We will learn about the parameterization in the xml file.

Suppose we want to set the global variables such url settings, username, password or API Keys, there are some values which are constant in all the test cases, in such case we use the TestNG Parameters.

TestNG Parameters are present in the xml file. They can be applied either inside the tag or tag. If we want to apply the parameters to all the test cases, then the parameters are applied inside the tag. If the parameter is specific to a particular folder, then the parameter is applied within a tag.

Let’s understand through an example.

First case: When Parameters are applied below the tag.

Step 1: Open the Eclipse.

Step 2: We create three class files, i.e., Sum.java, Subtract.java, and Multiply.java.

Sum.java

Subtract.java

Multiply.java

Step 3: Now, we create the testng.xml file.

testng.xml

In the above testng.xml file, we pass the parameters which are valid to all the classes.

Step 4: Run the testng.xml file.

Output

TestNG Parameters

Second case: When parameters are specific.

Step 1: Open the Eclipse.

Step 2: We create two class files. i.e., Fruits.java and Vegetable.java.

Fruits.java

Vegetable.java

Step 3: Now, we create the testng.xml file.

In the above testng.xml, we specify the parameters in a particular folder means that the parameters are applied to those classes which are specific to that folder.

Step 4: Run the testng.xml file.

Output

TestNG Parameters


Next TopicTestNG Listeners

You may also like