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

Jonathan
  • 191
  • 2
  • 3
  • 8

5 Answers5

3

You can use the scripting feature to customize your response.

In the mockResponse window, you can click on the script menu.

In here you can put something like (using XPath to fully qualify the element you are looking for):

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

When you invoke the MockResponse, theValue variable should be automatically updated.

Manrico Corazzi
  • 11,299
  • 10
  • 48
  • 62
khylo
  • 4,430
  • 3
  • 29
  • 24
1

Using Dispatch SEQUENCE the MokcResponse can be:

<myResponse><yourValue>${#MockResponse#Request#//myValue}</yourValue></myResponse>
Edgar Aviles
  • 119
  • 2
  • 6
1

The question/answer of SoapUI getting request parameters in mock service script is almost the same. To summarize:

def req = new XmlSlurper().parseText(mockRequest.requestContent)
context.theValue = req.myRequest.myValue
Community
  • 1
  • 1
0x89
  • 2,940
  • 2
  • 31
  • 30
0

I'm not entirely sure of the context, which tool are you using?

We use Liquid XML Studio, which has a Web Services Test Client, which makes manually calling web services pretty straightforward, this kind of sounds like what your trying to do, but maybe you are trying to automate this process for testing?

Please provide a bit more info.

Simon

Sprotty
  • 5,676
  • 3
  • 33
  • 52
0

If you're using SoapUI Pro just place the cursor where you want the value to be inserted, then right-click and select the parameter from the request via the "Get data..." submenu. This feature however is only available in the Pro version. Using the freeware edition you should follow khylo's answer.

Robert

Robert Strauch
  • 12,055
  • 24
  • 120
  • 192