HashMap as Global Variable


I want to create a HashMap as Globally available variable for all the custom Keywords.

The scenario is such ==>
Each Custom Keyword denotes a test case. So at the end of Custom Keyword, I am entering its result status and other information in an excel file. Due to this there are lots of file read and write operations. The most appropriate solution seems to write all this data in HashMap and at the end of all test case executions, write the data to an excel file. But for this the HashMap must be common across all the keywords. How to do that?

The HashMap Structure is =>
HashMap<String, ArrayList<String, String, String>>

Please help

Look at this post and the Custom Keyword addGlobalVariable() and its use in the pandemic function there to get the idea of how to create global variables of any typing at runtime:

Do you want a single GlobalVariable that is shared by 3 custom keywords?


Do you want 3 GlobalVariables for 3 custom keywords (one GB per each CK)?

How do you want to name the GlobalVariable?

A fixed name for the GlobalVariable is acceptable?

Or do you want to name the GlobalVariable in sync with the name of custom keywords?

Is it OK for you to create GlobalVariables before executing test?

Or, do you want each custom keyword to create GlobalVariable for it runtime?

Yeah i need 1 global variable accessible to all custom keywords.
I have able to access in this way but the value is not updated in the global variable

its ok to create an empty global var of map type before executing test. But the hashmap global variable would be populated on test execution. But once all the tests are executed, I want to write all the key value pairs in excel. How to permanently set and update value to global variable?

Doing simply GlobalVariable.MapVariable =LocalMapVariable didn’t work
The changes aren’t reflected

This is the code
The global variable StoreResultMap is of type Map and default is [:]

The code executes successfully but the value of global variable is not updated throughout the code despite the statement
GlobalVariable.StoreResultMap = map

Please help.

Somewhere in your package create:

public class GlobalStuff {
  static Map G = [:]

Anywhere else you need access to G, …

import static my_package.GlobalStuff.*

This is exactly how I build out my global vars. It’s also how I write my reports to disk (not in excel but it’s essentially the same thing).


Hi, Thanks for the response.

It is working at suite level. When I execute two testcases one after another than in the second testcase the map is empty. But at suite level it is working fine.

Do you expect that the value of GlobalVariable is displayed changed from the initial value to new one in the GUI? See the attached screenshot.

The fact is, a GlovalVariable as a variable in Groovy script can be updated of course. You can see the latest value by the primitve println.

println GlobalVariable.name

But the latest value is NOT reflected on the GUI display. The GUI displays the “intial value” stored in a xml file <project dir>/Profiles/default.glbl. The file is NOT updated by your script.