TestNG – 17 || Passing multiple Parameters in testng xml.

We can also pass parameters via TestNG XML file. These could be accessible using @Parameters annotation. This has been used in combination with the <parameter> tag in XML File.

Parameters Annotation

Passing multiple Parameters in TestNG xml

Parameters in TestNG XML File

The process of using the Parameter is very simple. In the XML file, we have to use <parameter> tag which contains two attribute name and value as mentioned below. This <parameter> tag will be used under <test> tag.

<parameter name="OSName" value="Windows 10"></parameter>

We could see in the above example that defining parameter is similar to define any variable in the key/value pair.

@Parameters in Class file

Accessing the value from the XML file is too simple. We have to just call the variable using the name attribute. These name and value are the same which we have defined in the XML file. For this, we have to use @Parameters annotation in the program.


Code Example

Here we have taken a simple example with two methods of different annotations. It is basically to show how we could easily implement Parameters in our program.


package ParameterAnnotations;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

 * @author ashok.kumar
public class ParametersExample 
	public void getSystemInfo(String os,String ip)
		System.out.println("Operating System: "+os);
		System.out.println("IP Address      : "+ip);
	public void launchBrowser(String browser)
		System.out.println("Target Browser  : "+browser);


<?xml version="1.0" encoding="UTF-8"?>
<suite name="ParameterExampleSuite">
	<test name="Test1">
		<parameter name="OSName" value="Windows 10"></parameter>
		<parameter name="browserName" value="Chrome"></parameter>
		<parameter name="ipAddress" value=""></parameter>
			<class name="ParameterAnnotations.ParametersExample" />

Result Analysis

Result Analysis in Console.


Computer Basics:

Java Basics:

Java File Handling:

OOPs Concept:

Java Question And Answer:

Java Programs:

Selenium Tutorials:



288total visits,3visits today

Leave a Reply

Your email address will not be published. Required fields are marked *