Parameterization/Data Driven Testing Of Selenium Webdriver Test Using Excel

Parameterization or data driven test is must required affair of whatsoever software automation testing tool. If yous tin non perform information driven testing inwards whatsoever software automation tool thence it is biggest drawback of that tool. Till now, Selenium webdriver software automation testing tool has non whatsoever built inwards construction or method to parameterize your test. If yous know, nosotros can perform information driven testing using user extension inwards selenium IDE software testing tool. You tin sentiment practical event of selenium IDE parameterization attempt on THIS ARTICLE POST. To parameterize selenium webdriver test, We involve back upwards of Java Excel API. First of all, nosotros involve to configure eclipse. Configuration steps are every bit bellow.

Another means of information driven testing In selenium webdriver software testing tool Is using TestNG @DataProvider Annotation. VIEW STEPS OF DATA DRIVEN TESTING USING @DataProvider.

Step 1 : Download latest jxl.jar file
Current latest version of jexcelapi is 2_6_12. It may alter inwards time to come thence download link tin also change.

  • Click on THIS LINK to become to jexcelapi_2_6_12 page.
  • Click on jexcelapi_2_6_12.zip link every bit shown inwards bellow image. It volition start downloading zippo folder.
  • On completion of zippo folder download, extract that zippo folder. You volition find jxl.jar file within it.
Step ii : Add jxl.jar inwards your projection folder every bit a external jar.
  • Right click on your projection folder inwards eclipse together with become to Build Path -> Configure Build path -> Libraries tab -> Click on Add External JARs push together with select jxl.jar.
For detailed description alongside icon on how to add together whatsoever external jounce inwards your projection folder, You tin follow footstep ii of THIS POST .

Step iii : Download information file
I accept prepared event information file for parameterization. CLICK HERE to download information file together with salvage inwards your D: drive.

Step four : Import header files
All Bellow given header files are required for this example. Please include them inwards your header file listing if non included.
import java.io.FileInputStream; import java.io.IOException; import java.util.concurrent.TimeUnit; import jxl.Sheet; import jxl.Workbook; import jxl.read.biff.BiffException; import org.openqa.selenium.JavascriptExecutor;

Step five : Run bellow given event inwards your eclipse.
Bellow given event volition read information from D:\\MyDataSheet.xls file together with thence type that information inwards First Name together with Last Name text box 1 yesteryear one.

Last Name text box volition hold upwards disabled initially thence I accept used javascript executor to enable it. You tin sentiment practical event alongside description for the same on THIS LINK.

Copy bellow given @Test method purpose of information driven testing event together with supervene upon it alongside the @Test method purpose of event given on THIS PAGE(Note : @Test method is marked with pink color in that linked page).

@Test   world void attempt () throws BiffException, IOException, InterruptedException    {   //Open MyDataSheet.xls file from given location.    FileInputStream fileinput = novel FileInputStream("D:\\MyDataSheet.xls");   //Access offset information sheet. getSheet(0) describes offset sheet.   Workbook wbk = Workbook.getWorkbook(fileinput);   Sheet sail = wbk.getSheet(0);      //Read information from the offset information sail of xls file together with shop it inwards array.   String TestData[][] = novel String[sheet.getRows()][sheet.getColumns()];      //To enable Last Name text box.   JavascriptExecutor javascript = (JavascriptExecutor) driver;   String toenable = "document.getElementsByName('lname')[0].removeAttribute('disabled');";   javascript.executeScript(toenable);        //Type information inwards offset cite together with concluding cite text box from array.   for(int i=0;i<sheet.getRows();i++)   {    for (int j=0;j<sheet.getColumns();j++)    {     TestData[i][j] = sheet.getCell(j,i).getContents();     if(j%2==0)     {      driver.findElement(By.xpath("//input[@name='fname']")).sendKeys(TestData[i][j]);     }     else     {      driver.findElement(By.xpath("//input[@name='lname']")).sendKeys(TestData[i][j]);     }    }    Thread.sleep(1000);    driver.findElement(By.xpath("//input[@name='fname']")).clear();    driver.findElement(By.xpath("//input[@name='lname']")).clear();   }   Thread.sleep(1000);      }

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