Я пытался создать GlobalVariable динамически после сообщения в https://docs.katalon.com/katalon-studio/docs/create-global-variables-on-the-fly.html.
Определение ключевого слова:
public class Helper {
@Keyword
void addGlobalVariable(String name, def value) {
GroovyShell shell1 = new GroovyShell()
MetaClass mc = shell1.evaluate("internal.GlobalVariable").metaClass
String getterName = "get" + name.capitalize()
mc.'static'."$getterName" = { -> return value }
mc.'static'."$name" = value
}
Код сценария:
CustomKeywords.'Helper.addGlobalVariable '(' localURL ',' katalon.com ')
println GlobalVariable.localURL
Я получаю следующую ошибку
2019-03-21 14:56:24.433 [39mDEBUG[0;39m [36mify if an contract can be deleted -[0;39m [39m1: Helper.addGlobalVariable("localURL", "katalon.com")[0;39m
internal.GlobalVariable
2019-03-21 14:56:24.659 [34mINFO [0;39m [36mk.k.c.m.CustomKeywordDelegatingMetaClass -[0;39m [39mHelper.addGlobalVariable is PASSED[0;39m
2019-03-21 14:56:24.659 [39mDEBUG[0;39m [36mify if an author contract can be deleted -[0;39m [39m2: println(BaseURL)[0;39m
http://dev.dewdropsbff.zycus.net/api
2019-03-21 14:56:24.662 [39mDEBUG[0;39m [36mify if an contract can be deleted -[0;39m [39m3: println(localURL)[0;39m
2019-03-21 14:56:24.671 [1;31mERROR[0;39m [36mc.k.katalon.core.main.TestCaseExecutor -[0;39m [31m❌ println(localURL) FAILED.[0;39m
[31mReason:[0;39m
[31mgroovy.lang.MissingPropertyException: No such property: localURL for class: internal.GlobalVariable[0;39m
[31m at Verify if an author contract can be deleted.run(Verify if an author contract can be deleted:23)[0;39m
[31m at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)[0;39m
[31m at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)[0;39m
[31m at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:331)[0;39m
[31m at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:322)[0;39m
[31m at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:301)[0;39m
[31m at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:293)[0;39m
[31m at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:227)[0;39m
[31m at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)[0;39m
[31m at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)[0;39m
[31m at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)[0;39m
[31m at TempTestCase1553160381933.run(TempTestCase1553160381933.groovy:21)
Пожалуйста, дайте мне знать, как это исправить. Спасибо.