如何通过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.
这是我到目前为止尝试过的
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
首先按照如下所示的常规设置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屋!