Hi All, I’m new to Katalon and I can safely say that it is amazing!!! I do hope to learn more and contribute to this amazing platform in the near future.
Issue:
How do I dynamically convert all my global variables to a Map List (Map<Obj,Obj>) .
Reason:
I need to pass variables to my Object Repository using findTestObject. My issue is that for each profile I may/maynot have a variable and I wish not to stop my automated test because a variable/feature is not part of a respective environment.
Example below of what I’m trying to accomplish.

Reference: findTestObject
image.png
Please share some of your GlobalVariable name and value pairs. I need them for writing a readable description.
Please try the following test case:
import java.lang.reflect.Fieldimport com.kms.katalon.core.configuration.RunConfigurationimport groovy.json.JsonOutputimport internal.GlobalVariable as GlobalVariable// Name of Execution Profile// e.g, 'default'String profileName = RunConfiguration.getExecutionProfile()// Map which contains GlobalVariables defined by the current profileMap keyValuePairs = [:]// use Java Reflection APIClass clazz = GlobalVariable.classField[] fields = clazz.getFields()for (Field field: fields) { String name = field.getName() Object value = field.get(GlobalVariable) if (!name.startsWith('__') && value != null) { keyValuePairs.put(name, value) }}// Map with the name of current profile combined with the keyValuePairsMap executionProfile = [:]executionProfile.put(profileName, keyValuePairs)// show the resultSystem.out.println(JsonOutput.toJson(executionProfile))
When I ran it, I got the following output:
{"default":{"G_var1":"in the default profile","G_var2":"in the default profile"}}
or
{"another":{"G_var1":"hello","G_var2":999,"G_var3":["\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u0435","\u0441\u043f\u043e\u0441\u0438\u0431\u043e"]}}
1 Like
kazurayam said:
Please share some of your GlobalVariable name and value pairs. I need them for writing a readable description.
Here are a few examples: AM_HOST, AM_PORT, AM_PATH
Solomon,
Please try the code which I posted at 11/23/2018.
It will print something like this:
{"default":{"AM_HOST":"demoaut.katalon.com","AM_PORT":"80","AM_PATH":"/login"}}