Forum Discussion

AlekseiKlimkin's avatar
AlekseiKlimkin
Occasional Contributor
8 years ago

Get MockResponse as a String in the Response script

Hi Everyone,

Not sure if this question has never been asked before. If so, please provide me with an approproate address.

 

I need to set a MockService property from a MockResponse, so that I can use it in the dispatch script for the next mock operation.

For that I am trying to read the response as a string and put a value from that response to the MockService property.

 

How can I get my response as a string in this case?

I tried to look here for an answer https://www.soapui.org/rest-testing-mocking/mock-service-scripting.html but to no avail.

 

Here is what I've tried:
https://www.soapui.org/apidocs/com/eviware/soapui/model/mock/MockResponse.html#getResponseContent()

def response = MockResponse.getResponseContent();
String id = response.Flights[0].Id;
log.info(id);
def mockService = mockRunner.mockService;
mockService.setPropertyValue("myId", id);

Also, I tried to use json slurper to parse the response as a text as I do in testcase scripts and assertion scripts.

 

Neither of these seem to work, though.

I am pretty sure the answer should be quite obvious, but I cannot find it for some reason.

  • nmrao's avatar
    nmrao
    Icon for Champion Level 2 rankChampion Level 2
    Not sure if I got the question.

    Can you explain the issue with image or screen shot comments?
    • AlekseiKlimkin's avatar
      AlekseiKlimkin
      Occasional Contributor

      Hi! I'll try to explain further.

       

      I have a Mock Service with a bunch of Mock Operations.

      Here we are considering one particular operation with a few Mock Responses.

       

      The decision about which Response is chosen is made in dispatch script for this mock operation.

       

      After the response is given to a user I'd like to write a value from this response (id in the above case) to a MockService property.

      I need to do that because the next mock operation in the cycle chooses which response to give to a user based on this id.

       

      So when the first mock operation completes, I want to use the value of a given id and set it to the MockService property.

      Does it make the things clearer?