Wednesday, 17 April 2013

Using Apache POI for Data driven testing in Selenium Webdriver

Selenium is probably the most famous open source tool for Web testing.This blog post is how to use POI in selenium web driver so that data driven testing can be performed.

Why Excel?

Excel is probably the most commonly used tool for working with test data.

You can find more about Apache POI at

Code is self-explanatory,documented for understanding and is hosted at Github

Code for XLS files:

Code for XLSX files :

The above code assumes that you have a structure to your excel files.The two-dimensional array gives you great control over the way you can iterate over the rows and columns of the excel file and this control comes when you have structure to your test data file,but if there is any blank cell in the middle, there is a null pointer exception that is thrown since the code assumes that the file is structured.We can add a handler here by means of a missing cell policy, but that would make the very purpose of using the two dimensional array as a backend structure meaningless.

If you dig into Apache POI a little more, you would be tempted to use its capabilities such ignoring blank cells and so on,but its a lot easier to maintain the excel file in a specified format rather than writing code to handle the brittleness of the excel file itself.The two dimensional structure forms a model through which you can build a data driven framework on top of excel using Apache POI.

If you face any issues,do let me know by commenting here or dropping me an email.

No comments:

Post a Comment