β Join us - https://sendfox.com/thetestingacademy
In this video, We are going to learn Data Driven Framework in Selenium(with Example Code).
How to implement Data Driven Framework in Selenium using Apache POI and TestNG data provider?
π Day 30 Task: Explain the Data-Driven Framework in With Selenium.
π Thread: https://scrolltest.com/automation/day26
π All Task List: https://scrolltest.com/automation/task
π Watch Full Playlist: https://apitesting.co/30days
πDownload MindMap: https://scrolltest.com/Titb
β
What is Data Driven Framework?
Separating the test scripts logic and the test data from each other
Create the Automation Script by Passing Test Data
Test data set is kept in the external files
- Mysql
- Excel 3.JSON
- Text or config File
- XML file Script required logic to connect to TestData.
β
What is Apache POI?
The Apache POI Project's mission is to create and maintain Java APIs for manipulating various file formats based upon the Office Open XML standards (OOXML)
To read or write an Excel,Apache provides a very famous library POI. This library is capable enough to read and write both XLS and XLSX file format of Excel.
To read XLS files, an HSSF implementation is provided by POI library.
To read XLSX, XSSF implementation of POI library will be the choice. Let's study these implementations in detail.
β
Download Code - https://scrolltest.com/automation/day24
β
http://poi.apache.org
β https://mvnrepository.com/
πͺ Join our Community - http://bit.ly/learntesting2019
β
Automation Tester Community - https://thetestingacademy.com
π¦Follow us on Twitter - https://twitter.com/itstechmode
π Like us on Facebook - https://www.facebook.com/scrolltest
π€ Listen to our Podcast - https://anchor.fm/thetestingacademy
package com.scrolltest;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
public class DDT {
private WebDriver driver;
private XSSFWorkbook workbook;
private XSSFSheet sheet;
private XSSFCell cell;
public DDT() {
}
@Test(priority = 0)
public void testFullPage() throws IOException {
File file = new File("src/main/java/com/scrolltest/TD.xlsx");
FileInputStream fis = new FileInputStream(file);
workbook = new XSSFWorkbook(fis);
sheet = workbook.getSheetAt(0);
for (int i = 1; i <= sheet.getLastRowNum( ); i++) {
cell = sheet.getRow(i).getCell(0);
DataFormatter formatter = new DataFormatter();
String username = formatter.formatCellValue(cell);
cell = sheet.getRow(i).getCell(1);
String password = formatter.formatCellValue(cell);
driver.findElement(By.name("userName")).sendKeys(username );
driver.findElement(By.name("password")).sendKeys(password );
driver.findElement(By.name("submit")).click( );
driver.manage( ).timeouts( ).implicitlyWait(3, TimeUnit.SECONDS);
Assert.assertTrue(driver.findElement(By.linkText("SIGN-OFF")).isDisplayed( ));
driver.findElement(By.linkText("SIGN-OFF")).click();
}
}
@BeforeTest
public void beforeTest() {
driver = new FirefoxDriver( );
driver.get("http://demo.guru99.com/test/newtours/index.php");
driver.manage( ).window( ).maximize( );
driver.manage( ).timeouts( ).implicitlyWait(5, TimeUnit.SECONDS);
}
@AfterTest
public void afterTest() {
driver.quit( );
}
}
--
Be sure to subscribe for more videos like this!
Top comments (0)