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:
But unfortunately glist.get returns null. Tried other syntaxes like glist 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.
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:
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.