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>>
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:
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?
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
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.
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.