🔥 How to Implement Data Driven Framework in Selenium Using Apache POI? 
Tags: testing, tutorial, webdev, beginners
Published: 2020-07-05 16:18:37

✅ 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

[![ Read Excel File in Selenium with Apache POI](https://i.imgur.com/N5ZMcmf.png
)](https://youtu.be/c4v3P3CfE0U "Read Excel File in Selenium with Apache POI") 

✅ 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
  1. Mysql
  2. Excel
  3.JSON
  4. Text or config File
  5. 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
------------------------------------------------------

```java
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!

[![ TheTestingAcademy](https://dev-to-uploads.s3.amazonaws.com/i/r7vcy6wbvyjbk1y1uu0o.png
)](https://www.youtube.com/TheTestingAcademy?sub_confirmation=1 "TheTestingAcademy")