In this section, we will be seeing how to write the code in selenium for reading data from an excel sheet and how you can write data to excel sheet. Now you can get started with writing your data driven tests. You are done adding your poi files to your project. Select all the Jar files in the main folder, and also the jar files under lib and ooxml-lib folders. Select Build Path->Configure Build Path.Ĭlick on ‘Add External Jars’ as shown in the below screen. How to add the Jar files to Project library?Īs I said you need to add all the above Jar files to your project file library in order to do data driven testing using Selenium. You have to import all these Jar files to the class path of your project in Eclipse. The folder structure you get will be like:Īpart from the Jar files you see in the above folder, you have some more Jar files within the lib folder and ooxml-lib folder. Once the download is done, extract the files to a folder so that you can import the POI jars to your project. You select the zip file under Binary Distribution. Next page, you get all the available downloads for Apache POI. Go to the Apache POI download page and select ‘The latest stable release’ link to download the latest version. WE will be using the classes and methods in the POI library for reading/writing our excel files. The POI library provides different implementations for reading and writing these file formats- The HSSF implementation is used for xls files and the XSSF implementation for xlsx files. The POI library lets you work with both xls and xlsx documents. It can also be used if you want to write any data to an excel file in your scripts. So for data driven testing using Selenium WebDriver, we use it for reading data stored in excel sheets. It has classes and methods to decode the user input data or a file into MS document files. What is Apache POI?Īpache POI is basically an open source Java library developed by Apache which provides an API for reading and writing files in Microsoft office formats including MS Word, Powerpoint or Excel using Java programs. For reading data from excel files, we need to use Apache POI. But Selenium is more like a framework and we need to depend on other third part tools in order to accomplish our testing needs. One major difference between QTP/UFT and Selenium that we need to understand is QTP/UFT is a ready to use automation tool. Similarly most of the automation tools have mechanisms for reading data from external files and use it in test cases. If you are familiar with using QTP/UFT, it can read data from internal data sheets or external excel files. Storing data in an external file makes it easy to manage scripts easily and update data whenever needed without affecting the scripts. Headers = (Convert.ToString((range.Cells as Excel.Range).Value2)) Īrray = (Convert.ToString((range.Cells as Excel.Range).Data driven testing refers to storing the test data in some external file rather than hard coding it in the test scripts. ![]() XlWorkSheet = (Excel.Worksheet)_Item(wks) Int worksheetcount = įor (int wks = 1 wks <= worksheetcount wks++) The same element set can be used to get specific key value pairs as mentioned in the below post about how to read excelworkbook public static GetExcelData(string Workbook)ĭataSet SeleniumElementSet = new DataSet() Reads data in every sheet and stores it in a Table set.Loads the Workbook and reads the every sheet.Takes the Workbook variable and opens the workbook.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |