如何通过 groovy 动态更新 ReadyAPI/SoapUI 中的资源值? [英] How to update Resource value in ReadyAPI/SoapUI dynamically by groovy?
问题描述
我的资源采用这种格式testing/101/getCustomer/99"
my resource is in this format "testing/101/getCustomer/99"
这里我需要通过 groovy 动态更改101"和99"部分,以便我可以在同一个测试用例中运行多个值.我查看了 ReadyAPI 的内置功能,但没有那么有用.
Here I need to change "101" and "99" part dynamically by groovy so that I can run for multiple values in same test case. I looked into the ReadyAPI's built in feature, but it was not that helpful.
我也找到了这个链接,但是它改变了整个项目中的资源.我正在寻找的解决方案是在测试用例级别.因为我的每个测试用例都会有不同的 url.
I also found this link, but it changed the resource in the entire project. The solution I am looking for is in test case level. As my each test case will have different url.
https://community.smartbear.com/t5/SoapUI-Open-Source/How-to-set-the-resource-path-at-run-time-while...
任何帮助将不胜感激.
这是我迄今为止尝试过的
Here is what I have tried so far
import com.eviware.soapui.impl.rest.RestResource
import java.io.*;
def project = testRunner.testCase.testSuite.getProject()
String restServiceName = "Resource name" (From the Rest Request Properties)
List<RestResource> ops = project.getInterfaces()[restServiceName].getOperationList()
log.info("ops ::"+ops);
log.info("ops size ::"+ops.size());
for (RestResource restResource : ops) {
String pathStr = restResource.getFullPath();
log.info("pathStr first-->"+restResource.getFullPath());
restResource.setPath("testing/101/getCustomer/99");
if (pathStr.contains("101"))
{
restResource.setPath("testing/101/getCustomer/99");
restResource.setPath(pathStr.replace("testing/101/getCustomer/99", "testing/50/getCustomer/99"));
}
}
推荐答案
你可以使用 testCase 级别的属性
you could use a testCase level property
首先像下面这样通过groovy设置res的值
first set the the value of res by groovy like below
def x=101
def y=99
def res="testing/$x/getCustomer/$y"
testRunner.testCase.setPropertyValue("resourc",res)
现在设置了测试用例级别的属性.它可以在任何地方使用,如下所示
Now the testcase level property is set. It can be used as below wherever you want
${#TestCase#res}
这篇关于如何通过 groovy 动态更新 ReadyAPI/SoapUI 中的资源值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!