Assign global variable Map type in test suite

Hello,

I created a global variable “temporaryData” type Map but with no value.
In TC1, I assign values to temporaryData with:

  • GlobalVariable.temporaryData.put(‘K1’, ‘V1’)
  • GlobalVariable.temporaryData.put(‘K2’, ‘V2’)
    And the values are correctly assigned (checked on logs)

In TC2, I created 2 local variables K1 and K2 in Variables tab with the value:

  • K1: GlobalVariable.temporaryData.get(‘K1’)
  • K2: GlobalVariable.temporaryData.get(‘K2’)
    And the values are correctly retrieved with those assigned in TC1
    image

The problem is, I don’t want to assign the values for K1 and K2 in the variables tab of TC2. I want them to be a null string, but I want to assign the values in the test suite (where TC1 is ran first and TC2 ran after) but I don’t know how to do it and I tried many solutions. Because in the Variable Binding of test suite, I am not able to select method call or select specific key in my global variable when I used data type “Script variable”

Could you please help me to assign the keys of my global variable to my local variables of TC2 in the test suite ?

I’m not exactly sure what you mean as your problem, but I believe you do not want to set a default value for your GlobalVariables in your TC2. Is that correct? If it is, you do not have to. All you need is to define your GV in TC1 (and set a value) and ensure you have the below import statement at the top of TC2 and then your GV are already defined going into any TestCase associated with the TestSuite you are running.

import internal.GlobalVariable as GlobalVariable

In TC2, you can initiate your K1 and K2 as default empty strings. Do not initiate your GlobalVariables in TC2 at all.

def K1 = '';
def K2 = '';

Hello,

Thanks for your answer.
In fact I already defined the value of my GV in TC1, which works and I want to define the values in the Variable Binding of my test suite for TC2. Because in TC2, I only use my local variables but I want that the test suite initializes the values of the variables in TC2.
The aim is to separate test cases coding and data input. So in my test cases (TC1 and TC2) I only used the local variables which are initialized in my test suite. But, I cannot initialize my local variable in TC2 with my GV because KATALON doesn’t allow me to set the value.
In TC2 I can define it easily as show in my first print screen but I want to do the same in test suite, because in TC, I want to set K1 and K2 to ‘’ in order to not be dependent of a value.
I hope I’m clear, if not don’t hesitate.

Global Variables already are defined across all TestCases within a TestSuite if you include the import statement in the TestCase:

import internal.GlobalVariable as GlobalVariable

You do not need to Variable Bind your GV.

What may be your concern is that you are using same variable, like K1 and GV.K1. My suggestion is to change your local variable to something different like “myK1” or “localK1” so they are not the same. I have come upon many a mistake due to the use of a local variable with the same name as a class variable or GV. Fortunately, many coding review software will catch this type of error now-a-days.

Yes I know global variable is defined across all test cases, that’s why it works when I assigned one value of the GV as a value for my local variable in my test case.
But as I said, I want to separate test case code and data input, because the main reason is if the data input change, I don’t need to change the test case code, just only change the data input in my test suite.
And the reason why I put the same name for my local variable and my key value of my GV, is for keeping a alignment between local variable and the key name to assign. It works like this and I don’t want to change. It’s not confusing, it help to know which key of GV to assign without checking what was put as a key.

So, is there a solution to assign a specific key value of my GV in the test suite for my test case ?