Earn Money in 10 days

Selenium Videos

Protractor In Selenium

Livechat

Showing posts with label DataProvider for multiple classes. Show all posts
Showing posts with label DataProvider for multiple classes. Show all posts

Sunday, 27 March 2016

DataProvider in Multiple Classes

If you have to use one  dataprovider in multiple classes of your project so for that we need to make our dataprovider static and then after making it static we can use that in every class where we need.


You have to follow this rule only just make your data provider as static and give the name to your data provider .

@Test(dataProviderClass = YourDataProviderClassname.class,dataProvider = dataprovidername)


By this Program/code you can run your dataprovider in multiple classes

import org.testng.annotations.DataProvider;


public class dataProvider {

@DataProvider(name = "logintestdataprovider")
//give the name to your dataprovider.Here your dataprovider name = logintestdataprovider
public static  Object[][] getData(){
Object data[][] = new Object [3][2];
data[0][0] = "ritu7181";
data[0][1] = "password1";
data[1][0] = "ritu7180";
data[1][1] = "password2";
data[2][0] = "ritu7182";
data[2][1] = "password3";
return data;
}

}
Now next step is to call this dataprovider to your test class.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;


public class Registration {
@Test(dataProviderClass = dataProvider.class,dataProvider = "logintestdataprovider")
public void Login(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);
}

}
You can use that dataprovider in multiple classes you need.I have just use in one class you can use that in multiple classes.

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: