Wednesday, 3 September 2014

How to use @Parameters in TestNG

How to pass the Data to test script through xml 
            We can use @Parameters to pass the input through xml.

Steps:
       1. We have to create an xml to pass the parameters to pass the test data.
       2.We have to name the class which we are passing the parameters by passing attributes.
       3.We have to  call the attributes to pass the parameters as

For Example:-
package Testng;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class PassInputByXML {
@Test
@Parameters({"param1","param2"})
public void passInput(String param1, String param2){
    System.out.println(param1);
    System.out.println(param2);
}
}


testng.xml:


<suite name="Suite" parallel="none">
  <test name="Test">
    <parameter name="para1" value="seleniumpractice" />
    <parameter name="para2" value="5.0" />
      <classes>
          <class name="TestNg.PassInputByXML"/>
      </classes>
  </test>
</suite>


To know FAQ's on Selenium Please ClickHere
To know SQL's Queries Required For Testers Please ClickHere

No comments:

Post a Comment