首页 > 解决方案 > 基于 Groovy Result 响应的条件 Goto

问题描述

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

我想要的选项是 3 :

主动非主动停止

我有一个 groovy 脚本步骤来定义一个 UI 窗口来提示如下:

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

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

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

当前脚本的图像

关于我该怎么做的任何想法?

提前致谢

标签: if-statementgroovysoapui

解决方案


在您的情况下,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")
}

希望能帮助到你。


推荐阅读