TestNG Tutorials 46: Overriding Parameters in TestNG

Hello Folks,

In this post we will learn an important concept of parameters in TestNG.

We know that we can create parameterised methods in a TestNG class and pass parameters to these methods through testng xml. We can pass parameters at four levels:

  1. At suite level
  2. At test level
  3. At class level
  4. At method level

Parameter value at higher level will be overridden by value at lower level if same parameter is passed. For example: If we pass a parameter say “Param” with value say “value1” at suite level and also we pass value “value2” for same parameter “Param” at test level, then parameter “Param” will have value as “value2” at that test level.

We will see some examples below:

Scenario 1: Passing parameters at suite level:-

TestNG class:

[java]package Parameters;

import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class ParameterTest { @Test @Parameters({“testParameters1″,”testParameters2”}) public void testMethod(String testParameters1, String testParameters2) { System.out.println(“Paramters one for test method: “+testParameters1); System.out.println(“Paramters two for test method: “+testParameters2);

}