如何在SoapUi中动态配置REST模拟?

时间:2016-06-10 07:10:18

标签: rest mocking soapui

使用SoapUi我打算调用MockService,当Response配置为返回静态消息时,一切似乎都没问题。另一方面,如果我添加并发送一个参数(例如?PName = John),虽然我也将响应中的名称从“John”更改为$ {PName},但我什么都没得到(空字符串)。我在哪里做错了?请参阅随附的屏幕截图

谢谢你,enter image description here

2 个答案:

答案 0 :(得分:2)

以下是我将如何获取请求参数:

例如,用户正在传递一个名为test的查询参数,其值为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}"
}

在所有数据流中:

enter image description here

答案 1 :(得分:-1)

使用属性概念进行参数化。 Mock Services使用属性Value。 由于您的属性PName在任何级别的soapUI中都不存在于自定义属性中,因此您将获得NULL响应。

将属性PnameValue Project Level定义为

enter image description here

现在将您的测试请求值修改为enter image description here

添加带响应的模拟服务

enter image description here

启动模拟服务和触发操作。您也可以在SoapUI的任何级别使用基于属性值的不同响应。

如果能解决您的问题,请接受回答。