Data Driven Testing Using Data Provider Annotation of TestNG - Bug Reaper

                  Bug Reaper

Lean about Automation Testing,Selenium WebDriver,RestAssured,Appium,Jenkins,JAVA,API Automation,TestNG,Maven, Rest API, SOAP API,Linux,Maven,Security Testing,Interview Questions

Wednesday 15 October 2014

Data Driven Testing Using Data Provider Annotation of TestNG

@DataProvider Is TestNG annotation. @DataProvider Annotation of testng framework provides us a facility of storing and preparing data set In method.

Below Snippet is the example of Login on Facebook using Data Provider of TestNG.

@DataProvider(name="myprovider") 


public Object[][] testdata()  


{   Object[][] testing={ {"hello","1"},{"hi","2"} };// two dimensional array to store Test Data   

return testing;  

}    

@Test(dataProvider="myprovider")   

public void testfunction(String username,String password)  

{   ProfilesIni allProfiles = new ProfilesIni();   

FirefoxProfile profile = allProfiles.getProfile("neeraj");

FirefoxDriver driver= new FirefoxDriver(profile);   

driver.get("http://facebook.com");   

driver.findElement(By.id("email")).click();   

driver.findElement(By.id("email")).sendKeys(username);   

driver.findElement(By.id("pass")).click();   

driver.findElement(By.id("pass")).sendKeys(password);

}  

No comments:

Post a Comment