How to use Dataprovider Annotation in Selenium TestNG


If you want to provide the test data, the DataProvider way, then we need to declare a method that returns the data set in the form of two dimensional object array Object[][]. The first array represents a data set whereas the second array contains the parameter values.
The @Test method that wants to receive data from this DataProvider needs to use a dataProvider name equals to the name of this annotation.

Here I am providing a sample snippet

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.DataProvider;

public class dataprovider
{

@DataProvider(name=”datainput”)
public String[][] login()
{
return new String[][]{
{“Dollar1234″,”william133143”},{“Dollar”,”Charan”},{“Invalid”,”Valid”}};
}

@Test (dataProvider=”datainput”)

public void login1(String uid, String pass)
{
WebDriver fd=new FirefoxDriver();
fd.get(“http://www.yahoomail.com”);
fd.findElement(By.id(“username”)).sendKeys(uid);
fd.findElement(By.id(“passwd”)).sendKeys(pass);
fd.findElement(By.id(“.save”)).click();
fd.close();
}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s