I will store the following variables in the LoginData sheet: The first one is the “invalid username” and “invalid password” test. In this example, I will modify our login scenarios (tests). Now, it is time to construct our test excel data file for data-driven testing. We have to do it in related test classes because each test class may have different test data. We need to set the sheet name before starting the tests. I should also add testDataExcelFileName in ExcelUtil class because all tests use the same excel file but their sheets are different. It creates FileInputStream and set excel file and excel sheet to excelWBook and excelWSheet static void setExcelFileSheet(String sheetName) Step-3: Set Data Excel File Name in BaseTest Class This method has two parameters: "Test data excel file name" and "Excel sheet name" Public static int columnNumber //Column Number Private static XSSFCell cell //Excel cell Private static XSSFSheet excelWSheet //Excel Sheet Private static XSSFWorkbook excelWBook //Excel WorkBook Public static String testDataExcelPath = null //Location of Test data excel file Public static final String currentDir = System.getProperty("user.dir") //Main Directory of the project Public static final String testDataExcelFileName = "testdata.xlsx" //Global test data excel file Here is the implementation of ExcelUtil Class: package utils.excelutils SetCellData: This method gets an excel file, row, and column number and sets a value to that cell. GetRowData: This method takes row number as a parameter and returns the data of the given row number. We are passing row numbers and column numbers as parameters. GetCellData: This method reads the test data from the Excel cell. It creates FileInputStream and set excel file and excel sheet to excelWBook and excelWSheet variables. SetExcelFileSheet:This method has two parameters: “ Test data excel file name” and “ Excel sheet name“. In this file, I wrote all excel operation methods. In order to manipulate excel files and do excel operations, we should create an excel file and called it “ ExcelUtil” under excelutils package as shown below. In order to use Apache POI libraries in your project, you should add required dependencies into your pom.xml as shown below. ) At the end of the article, if you have any problems or questions, please write a comment. Don’t worry, I will do my best and I hope you will get the topic without any problem. You can find the project on GitHub, I will share the project repository link at the end of the article. Here is the final snapshot of our project. In order to do that, we will add an ExcelUtil class, and this class does all kinds of excel operations. In this post, we will add excel manipulation capability to that project. I will go on with our Allure reporting example, which comprises of Page Object Model (POM) pattern, ExtentReports, and Allure Report features. Data Driven Framework in Selenium Architecture If our tests contain not too much data, we may use the TestNG data provider, but if we have more data, we should think to use excel files or we can store the test data in a database. I will show you how to integrate Apache POI libraries into our selenium test project. public static XSSFSheet readExcel(String Path, String SheetName) Write data in excel in java.How to create Data Driven Framework in Selenium with Apache POI Library? Yes, in this article, we will learn how to use excel files in your test automation projects for Data Driven Testing in Selenium. In order to read from an excel file and write to an excel file, we can use Apache POI Library.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |