如何在SoapUi中动态配置REST模拟? [英] How to dynamically configure a REST mock in SoapUi?
问题描述
使用SoapUi我打算调用MockService,并且当Response配置为返回静态消息时,一切似乎都很好.另一方面,如果我添加并发送参数(例如?PName = John),尽管我还将响应中的名称也从"John"更改为$ {PName},但我什么也没得到(空字符串).我在哪里做错了?请参阅所附的屏幕截图
Using SoapUi I intend to make a call to a MockService and when the Response is configured to return a static message, everything seems to be fine. On the other side, if I add and send a parameter (Eg. ?PName=John), although I also changed the name in the response from "John" to ${PName}, i get nothing (an empty string). Where am I doing it wrong? Please see the attached screenshot
谢谢您,
推荐答案
以下是获取请求参数的方法:
Here is how I would get the request parameters:
例如,用户正在传递值为abc
的查询参数,例如test
.
For example, user is passing a query parameter say test
with value abc
.
模拟脚本:
//Read request parameter test and assign value to a variable
def userValue = mockRequest.httpRequest.getParameter('test')
//Assign the input value to response context
context.requestValue = userValue
使用上下文示例响应:
{
"comment" : "${requestValue}"
}
所有数据流:
这篇关于如何在SoapUi中动态配置REST模拟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!