TestNG Parameter – Parameterization in TestNG using testng.xml

  • TestNG Parameter

TestNG Parameter: Important topic under testNG Framework is TestNG Parameter. It is an interesting features in automation testing and it is very much needed to test hugely large number of  times with different types of  data’s.

Previous article: TestNG Benefits and Annotations  , TestNG Prioritization and Sequencing

Same test with different data’s

TestNG Parametric (TestNG Parameter) test lets you to pass the same test with different options. Hence you can easily pass different data’s in a same test.

How it is done?

TestNG Parameter has two different types of methods to does that,

  •  With testing.xml
  • With Data Providers

Using testing.xml to pass parameters

 In this process the

  • first step is to define the simple parameters in the testing.xml file.
  • Once it is define then make a reference of those file with the source file.

How to do it…

Below simple login example will describe about clearing the authentication for both Username and Password.

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.Test;

import org.testng.annotations.Parameters;

public class TestngParameters {

private static WebDriver driver;

@Test

@Parameters({ “sUsername”, “sPassword” })

public void test(String sUsername, String sPassword) {

driver = new FirefoxDriver();

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

driver.get(“http://www.store.demoqa.com”);

driver.findElement(By.xpath(“.//*[@id=’account’]/a”)).click();

driver.findElement(By.id(“log”)).sendKeys(sUsername);

driver.findElement(By.id(“pwd”)).sendKeys(sPassword);

driver.findElement(By.id(“login”)).click();

driver.findElement(By.xpath(“.//*[@id=’account_logout’]/a”)).click();

driver.quit();

}

}


Here the parameter passing happens using testNG.XML

<suite name=”Suite”>

<test name=”ToolsQA”>

<parameter name=”sUsername” value=”testuser_1″/>

<parameter name=”sPassword” value=”Test@123″/>

<classes>

<class name=”automationFramework.TestngParameters” />

</classes>

</test>

</suite>

So now while running TestNG parameter will find the parameter named username and password.

Upcoming article: TestNG Data Provider

Learn Selenium Automation Tool from basics – FREE Selenium Tutorials

PDF Download the latest updated topics in Selenium – Download Link