How to dynamically configure a REST mock in SoapUi

2019-07-16 13:39发布

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

Thank you,enter image description here

2条回答
Fickle 薄情
2楼-- · 2019-07-16 14:18

Here is how I would get the request parameters:

For example, user is passing a query parameter say test with value abc.

Mock Script:

//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

Sample response using the context:

{
  "comment" : "${requestValue}"
}

Over all flow of data:

enter image description here

查看更多
等我变得足够好
3楼-- · 2019-07-16 14:21

Use concept of properties for parametrisation. Mock Services uses the properties Value. As your property PName is not present in Custom Properties at any level of soapUI, so you are getting NULL response.

Define a property PnameValue Project Level as

enter image description here

Now modify your Test Request value as enter image description here

Add a Mock Service with response

enter image description here

Start your mock Service and Trigger operation.Also you can you use different Response based on Property Values at any level of SoapUI.

Please Accept answer if it solve your problem.

查看更多
登录 后发表回答