TestNG DataProvider

An important features provided by TestNG is the DataProvider feature. It helps you to write data-driven tests, which essentially means that same test method can be run multiple times with different data-sets. Please note that DataProvider is the second way of passing parameters to test methods (first way we already discussed in @Parameters example). It helps in providing complex parameters to the test methods as it is not possible to do this from XML.
To use the DataProvider feature in your tests you have to declare a method annotated by@DataProvider and then use the said method in the test method using the ‘dataProvider‘ attribute in the Test annotation.
The below test class contains a test method which takes two argument as input and opens firefox driver and provide guest/guest as input to the textbox field when executed. A DataProvider method is also available in the same class by using the@DataProvider annotation of TestNG. The name of the said DataProvider method is mentioned using the name attribute of the @DataProvider annotation. The DataProvider returns a double Object class array with two sets of data i.e. “guest” and “guest ”.

Right click and run the script as Testng suite
Output :




No comments:

Post a Comment

Note: Only a member of this blog may post a comment.