I would like to use a global list of global maps to manage test data, but I found some unexpected behaviour.
Let’s say I have a globalvar called glist which is a list, and a globalvar gmap as a map. The latter contains only one key (‘map_value’) for testing purposes.
I am trying to get the value from this map of the list, like:
GlobalVariable.glist.get(0).get(‘map_value’)
But unfortunately glist.get returns null. Tried other syntaxes like glist[0] or getAt but it is still null.
I can see from the glist.size() that it contains 1 element, but can’t reach the value unless it is something else but a global map.
But here is the tricky part, If I create a local list called locallist in a testcase and put the global gmap there, I can get the ‘map_value’ without problems.
locallist.get(0).get(‘map_value’)
This implies you have created 2 distinct properties in the internal.GlobalVariable object. That is:
GlobalVariable.glist of type List<Object>
GlobalVariable.gmap of type Map<String, Object>, which contains a string key map_value.
Am I right?
In this case, if you want to get the value of map_value out of GlobalVariable.gmap, you should write:
GlobalVariable.gmap['map_value']
If you write GlobalVariable.glist.get(0).get('map_value'), it will possibly return null or raise an Exception. Why? Because GlobalVariable.glist is empty, therefore GlobalVariable.glist.get(0) will be null.
On the other hand,
This means you created a single variable :
List<Map<String, Object>> locallist
You created the localist and GlobalVariable.glist different. Therefore it is natural that they behave differently.
This implies you have created 2 distinct properties in the internal.GlobalVariable object. That is:
GlobalVariable.glist of type List<Object>
GlobalVariable.gmap of type Map<String, Object> , which contains a string key map_value .
Am I right?
Yes, but glist contains 1 element, which is the GlobalVariable.gmap. That is why I mentioned that the glist.size() returns 1
Therefore I should get something back from glist.get(0), shouldn’t I?
I am afraid, you are wrong about the locallist variable as well.
You need to write
No.
Name
Type
Default value
1
locallist
List
[${GlobalVariable.gmap}]
But I am not very sure. If your code works, OK, don’t mind my comment
Katalon Studio is designed to do interpolation for a literal GlobalVariable.FOO in the Variables tab of a Test Case.
Katalon Studio is NOT designed to do interpolation for literal GlobalVariable.FOO in the Execution Profile.
Why? I don’t know. Ask Katalon Team.
But I can guess the reason. The 2nd case: defining a property of the GlobalVariable object by referring to another property. It is problematic. You will easily make a circular reference as follows:
| name | value |
|:–|:–|:–|
| AAA | ${GlobalVariable.BBB} |
| BBB | ${GlobalVariable.AAA} |
What do you think how GlobalVariable.AAA can be evaluated?
AAA refers to BBB, which refers to AAA, which refers to BBB … never stops.