Multiple Test Cases in a Test Suite can share a Excel file to read/write data dynamically

I have made a demo project on GitHub:

-----------

Problems to solve

I wanted to find out a solution to the following points:

  1. I want my Katalon Studio project to generate a single Excel file where my Test Cases store anonymous data.
  2. I want to name the Excel file in such format. If I start a Test Suite named TS_a then 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 TC1 then it will create a file named TC1.xls without timestamp.
  3. I want 2 or more Test Cases in a Test Suite share a file and update it mutually. Test Case TC2 should not carelessly erase data written in the file by preceding Test Case TC1.
  4. I want to create sheet per each test case. If I have a Test Suite which contains 2 Test Cases TC1 and TC2, then running the Test Suite should result a Excel file containing 2 sheets: TC1 sheet and TC2 sheet.

Design note

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 TC1 sheet.

I found that combination of the following points solve the problem.

  1. 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.
  2. 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.
  3. Passing the HSSFWorkbook via GlobalVariable enables the Test Case TC3 updates the sheet created by preceding TC1 and TC2. Please read the source of TC3.
  4. Each Test Case should serialize the HSSFWorkbook object into file when they shutdown.
  5. 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.
5 Likes

Very nice!

If you use Katalon Studio 5.8.0 - 5.8.3, then this project will not work due to a defect of Katalon Studio. See

1 Like

… The Test Cases of a Test Suite can share the HSSFWorkbook object in the GlobalVariable during a Test Suite run.

Spark of genius, right there.

1 Like

Sudheer_D_J informed to me that the project (tagged as 0.1) is not working for him. I am checking it now …

1 Like

When I run the project with Katalon Studio 5.10.1, I got the following messages in the Consle:

2019-01-12 06:42:19.205 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2019-01-12 06:42:19.212 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/TC1
Caught: BUG! exception in phase 'semantic analysis' in source unit '/Users/urayamakazuaki/katalon-workspace/MultipleTestCasesSafelyWriteIntoExcelFile/Test Listeners/MyTestListener.groovy' ClassNode#getTypeClass for MyTestListener is called before the type class is set 
BUG! exception in phase 'semantic analysis' in source unit '/Users/urayamakazuaki/katalon-workspace/MultipleTestCasesSafelyWriteIntoExcelFile/Test Listeners/MyTestListener.groovy' ClassNode#getTypeClass for MyTestListener is called before the type class is set 
	at com.kms.katalon.core.ast.AstTextValueUtil.getTextValue(AstTextValueUtil.java:252)
...

This message is known by the following issue:

1 Like

I have fixed the problem in the demo project. Get the version with tag 0.2 at

1 Like

Having a Excel file as a dynamic data storage sharable by multiple test cases in a single test suite — this feature would be useful for many. My demo project shows the potential of this feature.

But the code in my demo is tricky and requires programming skill. People without programming skill would find it difficult to apply the technique to their own projects.

I would request Katalon Studio to provide the similar feature as built-in, so that it hides the configuration detail and let user just make use of it. Therefore I created a Feature Request at:

Upvote please if you like it.

3 Likes