if-statement - 基于 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")
关于我该怎么做的任何想法?
提前致谢
解决方案
在您的情况下,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")
}
希望能帮助到你。
推荐阅读
- angular - 将 Angular 文件部署到 Azure StorageAccount - 无法加载资源:
- r - 如何从数据框列中提取电子邮件 ID 并使用 R 自动发送邮件
- python - 通过运行 python 文件绘制 matplotlib
- c - 类型双关是函数指针未定义的行为吗?
- angular5 - 未设置猫头鹰日期时间值
- node.js - 如何在 DynamoDB 的 UpdateExpression 中将额外属性设置为 null?
- c# - 无法在 ASP.NET 5.0 中设置 cookie
- angular - 角度嵌套的 Observable
- datastage - 在 DataStage 11.7 中将字符串模式转换为空格
- wordpress - 通过“meta_value_num”订购 WP_Query,同时使用“offset”