DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Quality Engineering Design for AI Platform Adoption
  • High-Performance Java Serialization to Different Formats
  • Simplify Java Persistence Using Quarkus and Hibernate Reactive
  • Realistic Test Data Generation for Java Apps

Trending

  • Tactical Domain-Driven Design: Bringing Strategy to Code
  • Top JavaScript/TypeScript Gen AI Frameworks for 2026
  • Microservices: Externalized Configuration
  • The Network Attach Problem Nobody Warns You About
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. Data Parameterization Using Apache POI With Selenium

Data Parameterization Using Apache POI With Selenium

Take a look at how you can test both valid and invalid data for exploratory testing using Apache POI.

By 
Remi Andonissamy user avatar
Remi Andonissamy
·
Jun. 17, 19 · Tutorial
Likes (10)
Comment
Save
Tweet
Share
14.1K Views

Join the DZone community and get the full member experience.

Join For Free

Image title


Introduction

In testing, it is always important to test application features with different sets of data. Testing with one set of data that we use during recording or while creating a base script will not confirm the functionality of the application alone. For example: When we are doing a login test, it is extremely important to test with all possible valid and invalid credentials to ensure login functionality is working as expected.

One way to achieve testing multiple sets of data is to create individual test scripts/test cases that hold one set of hardcoded data. In this case, if we plan to test a functionality with ten different sets of data, we must create ten independent test scripts with different data. Another way is to create a base script with one set of data and manually change the data and execute the script 10 times.

Both approaches are time-consuming and practically difficult as well as impractical. The best and suggested approach to handling multiple sets of data is to have all the identified test data in any of the data sources like Excel, XML or in JSON files.

In this article, I’m going to discuss how to achieve data parameterization through Excel files using the Apache POI API.

Case Study

Peter is a newly-joined automation test developer in your Selenium project. He has performed exploratory testing on Tricentis Demowebshop application and trying to login with multiple users on the application. Can you guide Peter to complete his activity?

Here's the application URL.

Expectations

Help Peter to test the login screen with two sets of valid and one set of invalid credentials. A report in Excel with “Valid user” or “Invalid user” is generated based on the application functionality.

Sample Input Sheet:

Username Password Result
[email protected] abcd@1234
[email protected] pwd@1234
[email protected] abcd@1234                 


What is the Apache POI API?

  • It is an open source API of Apache Foundation

  • This API contains a huge collection of packages, classes, and methods that supports handling Excel files

  • This API supports both XLS and XLSX versions of Excel files by providing plenty of packages, classes and relevant methods to manipulate workbooks, sheets, etc.

  • Apache POI supports both .xls and .xlsx versions of Excel formats. HSSF is used to handle .xls files and XSSF is used to handle .xlsx files

How Do You Integrate the Apache POI in Eclipse?

There are two ways using which we can load the Apache POI libraries in Eclipse:

  1. Download/Add libraries to Java project from here.

  2. Use this Maven dependency in pom.xml file creating a Maven project

Image title

How to Read Data Using Apache POI

  1. The methods XSSFWorkbook  or HSSFWorkbook  are used to create a workbook object using FileInputStream . Workbook refers to the Excel file from where the data must be read.

  2. We can create a worksheet object using the method XSSFSheet or HSSFSheet. This refers to the sheet from where the data must be read.

  3. We can use the  .getmethod to work with rows and cells in the identified sheet.

How to Write Data Using Apache POI

  1. The methods XSSFWorkbook or HSSFWorkbook is used to create a workbook object using FileOutputStream . Workbook refers to the Excel file to which the data must be written.

  2. We can create a worksheet object using the method XSSFSheet or HSSFSheet. This refers to the sheet to where the data must be written.

  3. We can use the .get method to work with rows and cells in the identified sheet.

  4. The  .create method is used to create new cells and the .set method is used to insert values to cells.

  5. The close method is used to close the workbook.

Selenium code to handle Excel files:

Image title

Image title

Image title

Output Excel Sheet:

Username Password Result
[email protected] abcd@1234 Valid user
[email protected] pwd@1234 Invalid user
[email protected] abcd@1234 Valid user    


Summary

In this article, we have seen how to access Excel files in Selenium using Apache POI API. This code logic will iterate three times and writes "Valid" or "Invalid" user in "Result" column of the output Excel sheet. 

Apache POI Test data file IO application

Opinions expressed by DZone contributors are their own.

Related

  • Quality Engineering Design for AI Platform Adoption
  • High-Performance Java Serialization to Different Formats
  • Simplify Java Persistence Using Quarkus and Hibernate Reactive
  • Realistic Test Data Generation for Java Apps

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook