I have made a demo project on GitHub:
Problems to solve
I wanted to find out a solution to the following points:
- I want my Katalon Studio project to generate a single Excel file where my Test Cases store anonymous data.
- I want to name the Excel file in such format. If I start a Test Suite named
TS_athen it creates a file named
TS_afollowed by the timestamp when it was started. For example, it would be
TS_a.20180901_091020.xls. If I select a Test Case named
TC1then it will create a file named
- I want 2 or more Test Cases in a Test Suite share a file and update it mutually. Test Case
TC2should not carelessly erase data written in the file by preceding Test Case
- I want to create sheet per each test case. If I have a Test Suite which contains 2 Test Cases
TC2, then running the Test Suite should result a Excel file containing 2 sheets:
How can I make multiple Test Cases in a Test Suite safely share a single Excel file? Let me suppose a preceding Test Case
TC1 creates a sheet
TC1 in a Excel file, I do not want following Test Case
TC2 carelessly discard the
I found that combination of the following points solve the problem.
- Each Test Case on start-up should look for the target Excel file. If it find the file, it should open the file and update it. If it does not find the file, it should create new file.
- Use GlobalVariable.WORKBOOK. In the GlobalVariable I would put the object instance of HSSFWorkbook class (representation of Excel book by Apache POI). The Test Cases of a Test Suite can share the HSSFWorkbook object in the GlobalVariable during a Test Suite run.
- Passing the HSSFWorkbook via GlobalVariable enables the Test Case
TC3updates the sheet created by preceding
TC2. Please read the source of TC3.
- Each Test Case should serialize the HSSFWorkbook object into file when they shutdown.
- All of I/O processing to the Excel file are centralized in the MyTestListener. No Test Case makes I/O to the file. This design much simplifies the project and makes it easy to understand.