[英]Conditional Goto based on Groovy Result response
first of all, I'm not sure if this is possible but I want to make a groovy script to run conditionally to one or another step based on the groovy script result: 首先,我不确定这是否可行,但我想根据groovy脚本结果制作一个groovy脚本以有条件地运行到一个或另一个步骤:
The options I want to have is 3 : 我想要的选项是3:
Active Inactive Stop 主动不活动停止
I have a groovy script step to define a UI window to prompt like this: 我有一个groovy脚本步骤来定义一个UI窗口来提示如下:
def ui = com.eviware.soapui.support.UISupport;
def path = ui.prompt("Active Inactive or Stop","Title","");
def regResult = path
So based on what I type inside the popup window do the following: 因此,根据我在弹出窗口中输入的内容,执行以下操作:
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 当前脚本的图像
Any Ideas on how can I do this? 有关如何做到这一点的任何想法?
Thanks in advance 提前致谢
I realized how to do it: 我意识到该怎么做:
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")
}
The Switch Statement in Groovy is much powerful and much more cleaner in your case: Groovy中的Switch语句非常强大,在您的情况下更加清晰:
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")
}
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.