2

我的资源采用这种格式“testing/101/getCustomer/99”

在这里,我需要通过 groovy 动态更改“101”和“99”部分,以便我可以在同一个测试用例中运行多个值。我查看了 ReadyAPI 的内置功能,但它并没有那么有用。

我也找到了这个链接,但是它改变了整个项目中的资源。我正在寻找的解决方案是在测试用例级别。因为我的每个测试用例都会有不同的 url。

https://community.smartbear.com/t5/SoapUI-Open-Source/How-to-set-the-resource-path-at-run-time-while ...

任何帮助将不胜感激。

这是我到目前为止尝试过的

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"));
        } 

}
4

1 回答 1

0

您可以使用 testCase 级别的属性

首先通过 groovy 设置 res 的值,如下所示

def x=101
def y=99
def res="testing/$x/getCustomer/$y"
testRunner.testCase.setPropertyValue("resourc",res)

现在设置了测试用例级别属性。它可以在任何你想要的地方使用如下

${#TestCase#res}
于 2018-03-27T02:37:51.010 回答