如何在 SoapUI context.expand 表达式中使用嵌套参数?

How to use nested paramter in SoapUI context.expand expression?

我的用例是我想在多个 SoapUI 项目中批量更新请求主体。

请求正文示例。

{
 "name": "${#TestSuite#NameProperty}" 
 "id": "${#TestSuite#IdProperty}"
}

我想通过 Groovy 扩展 属性 ${#TestSuite#NameProperty} 并获取存储在 TestSuite 级别的值,然后根据需要修改它。

假设我的测试用例中有 50 个测试步骤,我想从 Groovy 脚本扩展每个步骤的请求。要展开特定的测试步骤,我会传递测试步骤的名称。例如:

expandedProperty = context.expand('${testStep1#Request}')

但是,如果我想遍历所有 50 个测试步骤,我怎样才能达到同样的效果呢?我尝试在 context.expand 表达式中使用嵌套参数,但它不起作用。例如:

currentTestStepName = "TestStep1"
expandedProperty = context.expand('${${currentTestStepName}#Request}')

这只返回了它上面测试步骤的扩展请求(我是 运行 来自 groovy 脚本的地方)而不是 "TestStep1" 步骤。 (这太疯狂了!)

此外,context.expand 似乎仅在通过 SoapUI 工作区项目的 Groovy 脚本执行时才有效。是否有其他方式或类似于 context.expand 的方法可以在无头执行期间扩展诸如“${#TestSuite#NameProperty}”之类的属性?例如:在 SoapUI 中导入的 groovy 编译后的 jar 文件。

提前感谢您的帮助!

您可以使用context.expand('${${currentTestStepName}#Request}')方式获取。

还有其他方法,不使用 context.expand。

为了获得任何给定测试步骤的单个测试步骤请求:

此处用户将步骤名称传递给变量stepName

log.info context.testCase.testSteps[stepName].getPropertyValue('Request')

如果你想获取测试用例的所有请求,这里是使用下面脚本的简单方法。

/**
 * This script loops thru the tests steps of SOAP Request steps,
 * Adds the step name, and request to a map.
 * So, that one can query the map to get the request using step name any time later.
 */
import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep
def requestsMap = [:]
context.testCase.testStepList.each { step ->
    log.info "Looking into soap request step: ${step.name}"
    if (step instanceof WsdlTestRequestStep) {
        log.info "Found a request step of required type "
        requestsMap[step.name] = context.expand(step.getPropertyValue('Request'))
    }
}
log.info requestsMap['TestStep1']

更新: 如果您感兴趣的步骤是 REST 步骤,请使用以下条件而不是上面的 WsdlTestRequestStep

if (step instanceof com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep) { //do the stuff }