Perfect Data Binding Workaround, Which Allows To Work With Any Data Easily

Hi guys,
I had a serious problem with Katalon Studio, that all TestCase variables are always binding as String from TestSuite to TestCase. And I couldn’t live with it, because it is painful to manually parse everything from String to desired data types. Funny thing is, that not even Boolean or Number works with data binding, but even if it was working, there is no support for custom data types.

So I had an idea, to use Description column in TestCase variables view to define desired data type like this:
(Notice, that I have type set to String for all variables)

These data types are supported, but you can easily add your custom data types (I’ll show it later):
String, Bool, Char, Byte, Short, Int, Long, Float, Double, LocalDate, LocalTime, LocalDateTime, ZonedDataTime, Period, Duration, List, Map and CustomData

All you need to do, is to download this file and put it your Keywords under some package (I put it in package called “_” so I can use it very quickly. (2.4 KB)

Then, it only requires small work at the beggining of project:

  1. Create these two global variables in you default profile:

CurrentTestCaseId of type String
CurrentTestCaseVariables of type Map

  1. Put these two lines to TestListener @BeforeTestCase method:
    public class TestListener {
    def beforeTestCase(TestCaseContext testCaseContext) {
    GlobalVariable.CurrentTestCaseId = testCaseContext.getTestCaseId()
    GlobalVariable.CurrentTestCaseVariables = testCaseContext.getTestCaseVariables()

And finally, you just have to put this line of code at the beginning of every TestCase, where you want to use automatic parsing of variables data types:
def d = __.Data.parse()

And then all TestCase variables are in object “d”, and already parsed to correct data type :smiley: So you can use it like this:

And if you want to use your custom data parser, just implement ITestDataParser and put it as default parser in Data.parse method (default is TestDataParser created by me)

And if you want your custom data to work with my TestDataParser, either imlement my ICustomTestData interface to provide your parsing logic, or just extend my JsonTestData class, which requires absolutely no work from your side and it will automatically parse your type from string using Json.

So to summarize, you can use easily any data types in your TestCase variables, which require a little bit of work at the beginning, but then it’s all just about making all your custom data types to extend JsonTestData and putting 1 line of code at the beginning of each TestCase. So usage is very easy :slight_smile:

And 1 last thing: the code I created is not superb yet, and I haven’t tested it thoroughly, but it seems to be working good. If you guys find any bugs, please tell me :slight_smile:
And if anybody of you want to improve this code, please also post it here, thanks :slight_smile:



I discovered, that there is @BeforeTestDataBindToTestCase method in TestListener.

So here is my TestListener now:

But be aware, that this method @BeforeTestDataBindToTestCase will run only if you run or debug your TestCase from TestSuite. If you run or debug just a single TestCase, this method won’t run at all…

And here is updated data file: (2.4 KB)

Now you don’t need to put anything to global variables, and you can use your variables in TestCase absolutely normally, like this:

So now it works very well, to summarize it, all you have to do, is to put that Data file to your keywords and create that @BeforeTestDataBindToTestCase method in TestListener. You this only once at the beginning of a project, and then you just write your data types to that Description column and use your variables in a normal way :slight_smile:

1 Like

I created another thread, because I don’t like, that I had to change the solution later and it’s a mess now.
If any of you moderators could please close this thread, thank you :slight_smile:

I created another thread here: