Earn Money in 10 days

Selenium Videos

Protractor In Selenium

Livechat

Saturday, 26 March 2016

Data Driven Testing using DataProvider

DataDriven Testing Using DataProvider

Testing with multiple sets of data is called data driven Testing.If you have to login with multiple username and password then we have to perform data driven testing.
By using  DataProvider annotation provided by TestNG we can perform Data Driven Testing.
DataProvider is one such feature in testng; it allows a test method to be executed with multiple sets of data.
DataProvider methods return two dimension object array.

@DataProvider
public Object[][] getData(){
Object data[][] = new Object [2][2];
//We have just initilize the data and this  new Object [3][2]; means 3 rows two colouns.
data[0][0] = "Username1";
//data at 0 row and 0 colomn.
data[0][1] = "password1";
data at 0 row and 1 colomn.
data[1][0] = "username2";
data at 1 row and 0 colomn.
data[1][1] = "password2";
data at 0 row and 1 colomn.
data[2][0] = "username2";
data at 2 row and 0 colomn.
data[2][1] = "password2";
data at 2 row and 1 colomn.
return data;

}
By using these code we can perform data driven Testing.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class datadriven {

@Test(dataProvider = "getData")
public void loginTest(String username,String password) throws InterruptedException{
WebDriver driver = new FirefoxDriver();
driver.get("https://gmail.com");
driver.findElement(By.xpath("//*[@id='Email']")).sendKeys(username);
Thread.sleep(5000);
driver.findElement(By.xpath("//*[@id='next']")).click();
Thread.sleep(3000);
driver.findElement(By.xpath("//*[@id='Passwd']")).sendKeys(password);
driver.findElement(By.xpath("//*[@id='signIn']")).click();
Thread.sleep(5000);
}

@DataProvider
public Object[][] getData(){
Object data[][] = new Object [3][2];
data[0][0] = "Username1";
data[0][1] = "password1";
data[1][0] = "username2";
data[1][1] = "password2";
data[2][0] = "username3";
data[2][1] = "password3";
return data;
}

}

5 comments:

  1. The Blog gave us idea about the data driven testing My sincere Thanks for sharing this post and please continue to share this kind of post
    Software Testing Training in Chennai

    ReplyDelete
  2. really you have been shared very informative blog. it will be really helpful to many peoples. so keep on sharing such kind of an interesting blogs.
    software testing training in chennai

    ReplyDelete
  3. Thanks for your informative post on selenium automation testing tool. Your article helped me a lot in understanding the future of automation testing tool and its career prospects. Selenium Training in Chennai | Software Testing Training in Chennai

    ReplyDelete
  4. The Blog gave us idea about the data driven testing My sincere Thanks for sharing this post and please continue to share this kind of post.

    Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium.


    Software Testing Training in Bangalore
    Software Testing Training in BTM Layout


    Software Testing Training in Marathahalli

    ReplyDelete
  5. Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.

    Software Testing Training in Marathahalli|

    Software Testing Training in Bangalore|

    ReplyDelete

Popular Posts

 
subscribe
Subscribe Us
emailSubscribe to our mailing list to get the updates to your email inbox... We can't wait more to have your email in our subscribers email list. Just put your nice email in below box: