Skip to end of metadata
Go to start of metadata

To create Global Variables during runtime using Katalon scripts, there are many approaches as discussed here. One of the approaches below comes from Sergii Tyshchenko:

"You can also define environment variable (with path to external configuration or properties file) in the session will be used to execute Katalon studio and then in the TestListener read the value of variable (path to the file), load that file and override settings for project, Global variables etc. To create new GlobalVariable I used metaprogramming:


void addGlobalVariable(String name, def value) {
    MetaClass mc = script.evaluate("internal.GlobalVariable").metaClass
    String getterName = "get" + name.capitalize()
    mc.static."$getterName" = { -> return value }
    //mc.static."$name" = value


It's possible to add getter/setter as new methods to GlobalVariable class or add new field (commented in this example)
Than in the script code you can use GlobalVariable.VarName where the VarName you new variable."
  • No labels