top of page

TestNG Tutorial

TestNG Parameters

What Are TestNG Parameters ?

TestNG parameters imply the use of '@parameters' annotation for parameterization in the test script.
Parameters are passed as an argument in the test methods whose values are provided in .xml file and we can pass more than one parameter in our annotaion.
Basic syntax of @Parameters annotaion :
  • For single value - @Parameters({"parameter_name"})

  • For multiple values - @Parameters({"param1","param2","param3"})

*In .xml, parameter is scoped to only suite or test tag. If parameter of same name is passed to both suite and test then priority is given to the value passed in test tag.

Let's understand this with an example :
  • First create a tesNG class named as 'ParametersExample' in which we have to automate this scenario :

* Launch Chrome Browser.

* Navigate to Google.

* Locate it's search bar.

* Search "Scope in Information Technology".

* Close the browser.

package testNGexamples;

import org.testng.annotations.Test; import org.testng.annotations.BeforeClass; import org.testng.annotations.Parameters; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import; import org.testng.annotations.AfterClass;

public class ParametersExample { WebDriver driver;


//Passing three parameters whose values are in .xml @Parameters({"url","locator","keyword"}) public void parameterExample(String url,String locator,String keyword) throws InterruptedException { driver.get(url); WebElement Search= driver.findElement(By.cssSelector(locator)); Search.sendKeys(keyword); Search.submit(); Thread.sleep(2000); }

@BeforeClass public void beforeClass() { System.setProperty("","..\\SeleniumJava\\drivers\\chromedriver99.exe"); driver=new ChromeDriver(); driver.manage().window().maximize(); }

@AfterClass public void afterClass() { driver.quit(); }


  • Create testNG.xml file for this test script :

<!DOCTYPE suite SYSTEM "" > <suite name="Test-Suite"> <test name="TestNG Demo"> <parameter name="url" value=""></parameter> <parameter name="locator" value="input[class='gLFyf gsfi']"></parameter> <parameter name="keyword" value="Scope in Information Technology"></parameter> <classes> <class name="testNGexamples.ParametersExample"></class> </classes> </test> </suite>

  • Now run .xml as TestNG Suite.

  • You would see the result.

Refer next page TestNG Data-Providers
bottom of page