How to pass user defined parameters from command line

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.

7 Likes