Using Apache POI to Test Banking Transactions

Yusuf Tayman
Nerd For Tech
Published in
4 min readMay 29, 2021

One of the most important things in the Banking as a Service platform is reporting and invoices. Reports are kept in different formats for each transaction and customers may want to use these reports at certain time intervals or in line with their needs.

In this article, I will show you how we can test transactions in excel format. First, let’s say you download sample transactions with selenium. Let’s look at how to compare values ​​through this transaction.

First of all, we will do this using Apache POI. Apache POI offers us libraries that allow us to process files in office document format. In this article, we will use Workbook and other interfaces related to excel, as we will be operating with excel.

Let’s assume we have a transactions file like the one below. Now, let’s start to process on this downloaded file.

Let’s create a helper, in which we will perform excel operations. After creating the class, we create a function as follows to open our file and switch to the sheet we want to work with. We create a file object and define it as a workbook object through the WorkbookFactory. Then, with the getSheet method offered by the Workbook interface, we switch to the sheet we want to work with. We define this to the currentSheet object. Now we will do all our operations on this currentSheet.

Let’s look at what format we will get the data in. there can be fields of different data types on excel such as boolean, numeric, etc. We want to keep them all as strings and compare them. You can also do this using switch-case. By the Cell interface, you can extract cells in the data type you want and then convert them.

Before reading our data, let’s first determine how many columns there are and add them to our project as an enum in order to be able to compare more easily. The reason we add them as enums is that we will use this enum when mapping.

Now we can move on to reading our data. Here we will read our data with filtering. In other words, we will be able to pull the rows we want with the column name we send from the outside and the value we want to filter.

As you can see below, we read everything by mapping. According to the filter we provide from outside, we read the data in excel and match the column name and values ​​and assign them to a list.

It’s time to compare the data we read through this excel with the values ​​we will give from outside. Now let’s look at how we wrote our final method. We send our transaction data, which we will compare from outside, and our data that we read from excel. We match our transaction data one by one in the form of key, values and compare it with the data we have taken from excel, and check whether their values ​​match.

Finally, let’s see how we will send and assert all these values from the outside. As you can see, we need to set the values we will give from the outside in the same way as key, value. This way we can assert all fields more easily.

We have defined the values as static for now, but it is very important that your tests are dynamic, otherwise, you may miss some cases in the future. Be careful to give these values dynamically as you use them in your tests.

Have fun with the Banking as Service platform tests. 🎊🎉

--

--