8

I have a mock response, which needs to return a value that was in the request. For example, this request can come in:

<myReqest><myValue>123</myValue></myRequest>

I already have a mockResponse:

<myResponse><yourValue>${theValue}</yourValue></myResponse>

I know how to set the value of ${theValue} through the context variable, but I can't figure out how to access the request and parse it for the value.

Any help would be much appreciated.

Thanks, Jonny

4

5 回答 5

3

您可以使用脚本功能来自定义您的响应。

在 mockResponse 窗口中,您可以单击脚本菜单。

在这里你可以放一些类似的东西(使用 XPath 来完全限定你正在寻找的元素):

context.theValue = 
mockRequest.getRequestXmlObject().selectPath("//Message/text()")[0];

当您调用 时MockResponsetheValue变量应该会自动更新。

于 2010-08-23T11:28:09.113 回答
1

使用 Dispatch SEQUENCE MokcResponse 可以是:

<myResponse><yourValue>${#MockResponse#Request#//myValue}</yourValue></myResponse>
于 2015-02-04T16:35:26.077 回答
1

SoapUI 在模拟服务脚本中获取请求参数的问题/答案几乎相同。总结一下:

def req = new XmlSlurper().parseText(mockRequest.requestContent)
context.theValue = req.myRequest.myValue
于 2010-11-23T19:06:22.607 回答
0

我不完全确定上下文,您使用的是哪个工具?

我们使用 Liquid XML Studio,它有一个Web Services Test Client,这使得手动调用 Web 服务变得非常简单,这听起来像是你想要做的,但也许你正试图自动化这个过程进行测试?

请提供更多信息。

西蒙

于 2010-08-06T10:14:50.073 回答
0

如果您使用的是 SoapUI Pro,只需将光标放在要插入值的位置,然后右键单击并通过“获取数据...”子菜单从请求中选择参数。但是,此功能仅在 Pro 版本中可用。使用免费软件版本,您应该遵循 khylo 的回答。

罗伯特

于 2010-10-19T19:55:05.197 回答