Parameterization in TestNG using testng.xml

Using testng.xml file we can also pass values to the argument of any test case or method. @Parameters annotation is used to pass parameters to a test case or method. Let us consider an example where we have written a test case say invokeBrowser which accepts an argument browserType. Based on the value passed respective Browser is invoked.

In testng.xml file a tagname called parameter is used which has an attribute called name and another its value.

Below is the example for testng.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "">
<suite name="Parameterization">
	<test name="Firefox testing">
		<parameter name="BrowserType" value="firefox"></parameter>
			<class name="testng.Parameterization"/>

Let us see the code for same:

package testNg;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class Parameterization {
	WebDriver Driver;
	@Parameters ("BrowserType")
	public void invokeBrowser(String sBrowserType){
			Driver = new ChromeDriver();
		} else if(sBrowserType.equalsIgnoreCase("firefox")){
			Driver = new FirefoxDriver();
		} else if (sBrowserType.equalsIgnoreCase("ie")){
			Driver = new InternetExplorerDriver();
		Driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

Here, an attribute called sBrowserType accepts value from an attribute BrowserType passed as firefox from testng.xml file.

If a method has multiple arguments, values from parameter attribute are accepted in sequential order.

PS: For any questions queries or comment feel free to write us at or Happy Learning 🙂

Saurabh Dhingra

About the Author

Saurabh Dhingra

Follow Saurabh Dhingra: