Data Driven Testing, where we driver our test script with different sets of data to validate different functionalities of the application.

CodedUI tool has in-built support to do data driven test from different sources, however I am going to put some light on NPOI libraries which helps to write your own code to develop driven driven test. NPOI is .NET version of POI Java project and it is totally free to use.

Before starting, you should have latest NPOI libraries which you can download from here…

Now you have to include NPOI libraries under your CodedUI Project > References and provide the reference in your C# class file also.

You are all set and now paste below code in your class file…

FileStream file;
private HSSFWorkbook ExcelWorkbook;
private ISheet ExcelSheet;
private ICell Cell;

public class TestDataFromExcel{

public void getData(){

file = new FileStream(“D://WorkBook/TestData.xls”, FileMode.Open, FileAccess.Read);
ExcelWorkbook = new HSSFWorkbook(file);
ExcelSheet = ExcelWorkbook.GetSheet(“Data”);
Cell = ExcelSheet.GetRow(0).GetCell(0);
String Username= Cell.StringCellValue;
} catch (IOException e) {

Console.WriteLine(“Exception caught: {0}”, e);



With above code, we can read any excel file (.xls) after providing Workbook location, Sheet Name, Row Number, and Cell Number.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s