基于 Groovy 结果响应的条件转到

Conditional Goto based on Groovy Result response

首先,我不确定这是否可行,但我想制作一个 groovy 脚本以 运行 有条件地执行基于 groovy 的一个或另一个步骤脚本结果:

我想要的选项是 3 :

活跃 无效 停止

我有一个 groovy 脚本步骤来定义一个 UI window 来提示这样的:

def ui = com.eviware.soapui.support.UISupport;
def path = ui.prompt("Active Inactive or Stop","Title","");
def regResult = path

因此,根据我在弹出窗口中输入的内容 window 执行以下操作:

If Active / Go to testRunner.gotoStepByName("InjectActive")
If Inactive / Go to testRunner.gotoStepByName("InjectInactive")
If Stop / Go to testRunner.gotoStepByName("Final Results")

Image of current Script

关于如何执行此操作的任何想法?

提前致谢

我知道怎么做了:

def result = testRunner.testCase.getTestStepByName("Where").getPropertyValue("result")

if (result == ("Active")) {
  testRunner.gotoStepByName("InjectActive")
} 
else if (result == ("Inactive")){
  testRunner.gotoStepByName("InjectInactive")
}
else if (result == ("Stop")){
  testRunner.gotoStepByName("Final Results")
}

Switch Statement in Groovy 在你的情况下更强大也更干净:

def result = testRunner.testCase.getTestStepByName("Where").getPropertyValue("result")

switch (result) {
    case "Active": testRunner.gotoStepByName("InjectActive"); break 
    case "Inactive": testRunner.gotoStepByName("InjectInactive"); break
    case "Stop": testRunner.gotoStepByName("Final Results"); break
    // in case result is null or empty
    case {!it}: testRunner.gotoStepByName("result is null or empty"); break
    // handle any other values
    default: testRunner.gotoStepByName("Unexpected value")
}

希望对您有所帮助。