Skip to toolbar

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.

@Parameters("OSName")

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.

ParametersExample.java

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

/**
 * @author ashok.kumar
 *
 */
public class ParametersExample 
{
	@BeforeTest
	@Parameters({"OSName","ipAddress"})
	public void getSystemInfo(String os,String ip)
	{
		System.out.println("Operating System: "+os);
		System.out.println("IP Address      : "+ip);
		
	}
	
	@Test
	@Parameters("browserName")
	public void launchBrowser(String browser)
	{
		System.out.println("Target Browser  : "+browser);
	}
}

ParameterXML.xml

<?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="10.11.1.1"></parameter>
		<classes>
			<class name="ParameterAnnotations.ParametersExample" />
		</classes>
	</test>
</suite>

Result Analysis

Result Analysis in Console.

TestNG:

Computer Basics:

Java Basics:

Java File Handling:

OOPs Concept:

Java Question And Answer:

Java Programs:

Selenium Tutorials:

JIRA:

Agile:


1955total visits,7visits today

Leave a Reply

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

Site Statistics

  • Users online: 0 
  • Visitors today : 4
  • Page views today : 4
  • Total visitors : 48,244
  • Total page view: 66,391

   YouTube ChannelQuora

            Ashok Kumar is working in an IT Company as a QA Consultant. He has started his career as a Test Trainee in manual testing in August 2010. Then he moves towards the automation testing after 4 years. He started learning JAVA and Selenium by self to get the knowledge of automation.

       While learning these tools and working on multiple projects, he found that sometimes people get stuck in live scenarios in their project and they have to do lots of RnD to get out of it. So he decided to start blogging only for such scenarios, where anyone facing any problem in their project, can ask any question or give a solution or you can say an alternate solution to achieve the goal successfully.

Later on, he observed that some people want to learn Java but they have few questions in their mind like how to start Java, whether we should go for the online or offline course. So he started writing tutorials on Java, Jira, Selenium, Excel etc.