Data driven testing Is most Important theme for all software testing automation tools because you lot demand to provide dissimilar develop of information In your tests. If you lot are using selenium IDE software automation testing tool in addition to you lot wants to perform information driven software testing inwards your software attempt out hence THIS POST. Now If you lot are using TestNG framework for selenium webdriver software testing tool then at that topographic point Is ane to a greater extent than or less other agency to perform data driven testing.
TestNG @DataProvider Annotation
@DataProvider Is TestNG annotation. @DataProvider Annotation of testng framework provides us a facility of storing in addition to preparing information develop In method. Task of @DataProvider annotated method Is supplying information for a attempt out method. Means you lot tin configure information develop In that method in addition to hence piece of job that information In your attempt out method. @DataProvider annotated method must render an Object[][] amongst data.
Let us run into uncomplicated event of information driven software automation testing using @DataProvider annotation. We receive got to practise 2 dimensional array In @DataProvider annotated method to shop information equally shown In bellow given example. You tin VIEW THIS POST to know to a greater extent than virtually 2 dimensional array In java.
Bellow given event volition yell upwards userid in addition to password ane yesteryear ane from @DataProvider annotated method in addition to volition feed them In LogIn_Test(String Usedid, String Pass) ane yesteryear one. Run this event In your eclipse in addition to notice result.
package Testng_Pack; 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.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; populace class Sample_Login { WebDriver driver = novel FirefoxDriver(); @BeforeTest populace void setup() throws Exception { driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); driver.get(" "); } @AfterTest populace void tearDown() throws Exception { driver.quit(); } //This method volition render 2 dimensional array. //This method behaves equally information provider for LogIn_Test method. @DataProvider populace Object[][] LoginCredentials(){ //Created 2 dimensional array amongst iv rows in addition to 2 columns. //4 rows represents attempt out has to run iv times. //2 columns represents 2 information parameters. Object[][] Cred = novel Object[4][2]; Cred[0][0] = "UserId1"; Cred[0][1] = "Pass1"; Cred[1][0] = "UserId2"; Cred[1][1] = "Pass2"; Cred[2][0] = "UserId3"; Cred[2][1] = "Pass3"; Cred[3][0] = "UserId4"; Cred[3][1] = "Pass4"; render Cred; //Returned Cred } //Give information provider method cite equally information provider. //Passed 2 string parameters equally LoginCredentials() returns 2 parameters In object. @Test(dataProvider="LoginCredentials") populace void LogIn_Test(String Usedid, String Pass){ driver.findElement(By.xpath("//input[@name='userid']")).clear(); driver.findElement(By.xpath("//input[@name='pswrd']")).clear(); driver.findElement(By.xpath("//input[@name='userid']")).sendKeys(Usedid); driver.findElement(By.xpath("//input[@name='pswrd']")).sendKeys(Pass); driver.findElement(By.xpath("//input[@value='Login']")).click(); String alrt = driver.switchTo().alert().getText(); driver.switchTo().alert().accept(); System.out.println(alrt); } }
testng.xml file to run this event Is equally bellow.
<suite name="Simple Suite"> <test name="Simple Skip Test"> <classes> <class cite = "Testng_Pack.Sample_Login"/> </classes> </test> </suite>
When you lot volition run to a higher house event In eclipse, It volition larn into UserID in addition to passwords ane yesteryear ane In UserId in addition to password text box of software spider web page. TestNG number study volition looks similar bellow.
http://www.software-testing-tutorials-automation.com/