We guide maintain already learnt how to practice in addition to use testng information providers In selenium webdriver examine cases In THIS POST. Also nosotros guide maintain used testng information providers In Selenium WebDriver Data Driven Framework creation thus all you lot are forthwith really familiar amongst testng information providers in addition to how to piece of occupation them In our automation examine instance creation.
Now supposing you lot guide maintain multiple examine cases in addition to each examine instance has Its ain information provider method to shop required information for that examine case. There Is non whatever Issue to piece of occupation information providers In this fashion but It Is non expert manner. It Is really difficult to cope information In this means because If you lot wants to alter information of few examine cases thus you lot guide maintain to opened upward all those examine cases files i past times i in addition to thus you lot tin alter them.
Best means to cope in addition to access examine information of all examine cases really easily Is : Store all information provider method In unmarried file. So whenever you lot wants to alter examine information of i or multiple examine cases, You postulate to opened upward alone unmarried file.
I guide maintain created unproblematic instance to shop examine information of ii unlike examine cases In unmarried file. First examine Is LogIn test(LogInCase.java) in addition to minute examine Is shape submission test(FormSubmit.java). Both examine cases postulate unlike examine information to execute examine instance in addition to I guide maintain created dissever file (dataProvider_Repository.java) to shop information provider methods of both examine cases equally bellow.
Create bellow hand iii course of written report file under TestNG_Advanced parcel In eclipse.
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 course of written report LogInCase { person 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.java course of written report file where dataProvider advert Is LogInData. @Test(dataProviderClass=dataProvider_Repository.class,dataProvider="LogInData") 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; 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 course of written report FormSubmit { person 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.java course of written report file where dataProvider advert Is FormData. @Test(dataProviderClass=dataProvider_Repository.class,dataProvider="FormData") 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 org.testng.annotations.DataProvider; populace course of written report dataProvider_Repository { //Test information to piece of occupation In LogInCase.java file. @DataProvider(name="LogInData") populace static Object[][] LogInCaseData(){ Object detail[][] = 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"; render detail; } //Test information to piece of occupation In FormSubmit.java file. @DataProvider(name="FormData") populace static Object[][] FormSubmitData(){ Object detail[][] = 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; } }
You tin come across that nosotros guide maintain created ii unlike @DataProvider methods In dataProvider_Repository.java file in addition to nosotros guide maintain accessed them In LogInCase.java in addition to FormSubmit.java files using syntax similar bellow.
@Test(dataProviderClass=dataProvider_Repository.class,dataProvider="LogInData")
@Test(dataProviderClass=dataProvider_Repository.class,dataProvider="FormData")
Now If you lot volition run LogInCase.java test thus It volition access information from LogInData @dataprivider method to execute examine in addition to testng out seat volition looks similar bellow at the terminate of examine execution.
Same way, When you lot run FormSubmit.java file, It volition access information from FormData @dataprivider method and examine execution effect volition looks similar bellow.
You tin relieve to a greater extent than @dataprivider methods In dataProvider_Repository.java file If you lot guide maintain to a greater extent than such examine cases.