Global list of global maps

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’)

thank you

This implies you have created 2 distinct properties in the internal.GlobalVariable object. That is:

  1. GlobalVariable.glist of type List<Object>
  2. 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:

  1. GlobalVariable.glist of type List<Object>
  2. 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 do not see what you mean by this.

Could you show us how you defined the GlobalVariable.glist. Could you show us screenshot of the definition panel of the Execution Profile?

And also please write a test case list this:

println "GlobalVariable.glist : " + GlobalVariable.glist

What do you see in the console when you execute this?

image
image
image

You can’t do this:

name value
glist [GlobalVariable.gmap]

By this, you will get

assert GlobalVariable.glist == [ null ]

Please note that [null] is a valid List object with size() == 1.


All you can do is to write:

name value
glist [ ["map_value": "map value"] ]

ah okey, thanks.

and what is difference here?
image

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


  1. Katalon Studio is designed to do interpolation for a literal GlobalVariable.FOO in the Variables tab of a Test Case.
  2. 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.

1 Like

Thank you for your time and effort explaining me how it works or should work:)
I’am going to find another way designing my test data