Using Single @DataProvider Method To Store All WebDriver Test Case Data

We cause got learnt how to exercise together with shop multiple @DataProvider methods In unmarried degree file called dataProvider_Repository.java together with and therefore nosotros tin john role those information In dissimilar seek out representative execution equally described In THIS PAGE. Using this, We tin john grapple information of all seek out cases real easily In unmarried file and If you lot wants to alteration seek out information of whatever seek out case, You cause got to alteration solely unmarried file.

Now, Instead of creating dissever @DataProvider method for each seek out case, Is It possible to shop all seek out cases information In single @DataProvider method? Yes nosotros tin john exercise It past times passing method advert In @DataProvider method equally shown In bellow example.

Create bellow given degree files under TestNG_Advanced package.

LogInCase.java
package TestNG_Advanced;  import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test;  populace degree LogInCase { soul static WebDriver driver;       @BeforeTest     populace void setUp() {         driver = novel FirefoxDriver();         driver.manage().window().maximize();         driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);         driver.get(" ");  }       //This LogIn method volition access information from dataProvider_Repository degree file where dataProvider advert Is BothData.     @Test(dataProviderClass=dataProvider_Repository.class,dataProvider="BothData")     populace static void LogIn(String UID, String PASS) {   driver.findElement(By.xpath("//input[@name='userid']")).sendKeys(UID);   driver.findElement(By.xpath("//input[@name='pswrd']")).sendKeys(PASS);;   driver.findElement(By.xpath("//input[@type='submit']")).click();   driver.switchTo().alert().accept();     } }

FormSubmit.java
package TestNG_Advanced;  import java.util.concurrent.TimeUnit;  populace degree FormSubmit { soul static WebDriver driver;       @BeforeTest     populace void setUp() {         driver = novel FirefoxDriver();         driver.manage().window().maximize();         driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);         driver.get(" ");  }       //This Submit method volition access information from dataProvider_Repository degree file where dataProvider advert Is BothData.     @Test(dataProviderClass=dataProvider_Repository.class,dataProvider="BothData")     populace static void Submit(String fname, String lname,              String email, String mobile,              String company) {      driver.findElement(By.xpath("//input[@name='FirstName']")).sendKeys(fname);   driver.findElement(By.xpath("//input[@name='LastName']")).sendKeys(lname);   driver.findElement(By.xpath("//input[@name='EmailID']")).sendKeys(email);   driver.findElement(By.xpath("//input[@name='MobNo']")).sendKeys(mobile);   driver.findElement(By.xpath("//input[@name='Company']")).sendKeys(company);   driver.findElement(By.xpath("//input[@type='submit']")).click();   driver.switchTo().alert().accept();     } }

dataProvider_Repository.java
package TestNG_Advanced;  import java.lang.reflect.Method;  import org.testng.annotations.DataProvider;  populace degree dataProvider_Repository {     //Pass Method advert In BothCaseData method.  @DataProvider(name="BothData")  populace static Object[][] BothCaseData(Method mtd){      Object detail[][] = null;      //If method advert = LogIn, Use this data.   if(mtd.getName().equalsIgnoreCase("LogIn")){        exceptional = novel Object[3][2];    detail[0][0]="UserName1";    detail[0][1]="Password1";       detail[1][0]="UserName2";    detail[1][1]="Password2";       detail[2][0]="UserName3";    detail[2][1]="Password3";   }   //If method advert = Submit, Use this data.   else if(mtd.getName().equalsIgnoreCase("Submit")){        exceptional = novel Object[3][5];    detail[0][0]="fName1";    detail[0][1]="lname1";    detail[0][2]="email1@youraccount.com";    detail[0][3]="mobno1";    detail[0][4]="company1";          detail[1][0]="fName2";    detail[1][1]="lname2";    detail[1][2]="email2@youraccount.com";    detail[1][3]="mobno2";    detail[1][4]="company2";        detail[2][0]="fName3";    detail[2][1]="lname3";    detail[2][2]="email3@youraccount.com";    detail[2][3]="mobno3";    detail[2][4]="company3";   }      render detail;  }  }

Test cases together with seek out information are same equally described In PREVIOUS EXAMPLE. But agency of storing seek out information together with accessing them In seek out cases Is different, Previously nosotros cause got created dissever @DataProvider method for both seek out cases. But forthwith nosotros cause got created unmarried @DataProvider method to shop information of both seek out cases. If else status volition banking corporation tally seek out method's advert together with based on that seek out information volition last provided.

Now you lot tin john operate both seek out cases 1 past times 1 to come across results.

More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post