Tuesday, 3 July 2018

TestNG Parameters

As we all know the value of Parameterization in automation testing. It allows us to automatically run a test case multiple times with various inputs and validation values. while creating a automation framework we need to put in some effort to support data driven testing in our automated tests. In this video we will see how we can parameterize a test case using TestNG parameters.

TestNG provides us interesting feature called TestNG Parameters. TestNG lets you pass parameters directly to your test methods with your testng.xml.

Video Tutorial -


How to do it?


Let me take a very simple example of Search on our site www.qaautomated.com, where the search text  is required to perform authentication.

1) Create a test case to perform Search which takes the one string argument as searchtext.

2) Provide searchtext as parameter using TestNG Annotation.



package test;


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
import org.testng.annotations.Parameters;
 
public class TestNGParameters{
 
 private static WebDriver driver;
 
  @Parameters("searchtext")
  @Test  
  public void test(String searchtext) throws InterruptedException {
 
   System.setProperty("webdriver.chrome.driver", "C:\\Softwares\\chromedriver_win32\\chromedriver.exe");
  
   driver=new ChromeDriver();
      
      driver.get("http://www.qaautomated.com");
 
      Thread.sleep(5000);
      driver.findElement(By.xpath("*//input[@class='search-field']")).sendKeys(searchtext);
      
      driver.findElement(By.xpath("*//input[@class='search-submit']")).click();
 
      driver.quit();
 
  }
 
}

3) Provide Search text value in testng.xml


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test thread-count="5" name="Test">
   <parameter name="searchtext" value="appium"/>
    <classes>
      <class name="test.TestNGParameters"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

4) Right click on testng.xml and run as TestNG Suit

0 comments:

Post a Comment