Forum Discussion

NewToSoap1's avatar
NewToSoap1
Occasional Contributor
8 years ago

How to save a dynamic mock response content to local drive

Hi All,

 

I am having a dynamic mock response under mock service. I want to save its content to my local drive. Please help me or suggest a way.

 

<soapenv:Body>
<mes:ResponseMessage>
<mes:Header>${Header}</mes:Header>
</mes:ResponseMessage>
</soapenv:Body>

I am using the below code to save the content but it is not working. It is not resolving the "${Header}". Please help me about how to save this response.

 

def resContent = mockResponse.responseContent.toString().trim();

def file = new File(filePath);

file.write(resContent, "UTF-8");

 

    • nmrao's avatar
      nmrao
      Champion Level 3
      Humble request for the author of this question. No need to spam, please.
      People will look at the posts and reply if they understand the question.
  • nmrao's avatar
    nmrao
    Champion Level 3
    Where do you have the above groovy script? In the Script Assertion of SOAP Request test step?
  • NewToSoap1's avatar
    NewToSoap1
    Occasional Contributor

    Hi Rao,

    Thanks for your reply.

     

    I am writing this script inside Script tab in mock Response for saving mock request and mock response. I used another script also which is not working too

    I used another script also which is not working too.

    def resContent = mockResponse.getMockResult().getResponseContent();

     

    Above script is always returning last mock response content but not the latest

     

    I am using all these scripts inside Script tab in mock response

     

    Regards,

    Mohit Bansal

    • nmrao's avatar
      nmrao
      Champion Level 3
      Not sure why are you saving in Mock service. Instead you should be doing it in test case.
  • NewToSoap1's avatar
    NewToSoap1
    Occasional Contributor

    Dear Rao,

    I am receiving 1000 of files in mock service and I have to save all the files on the local machine. So I am keeping saving code inside mock service. After saving mock request, I am creating a dynamic mock response and I want to save this response. To save this dynamic mock response, I am getting a problem. 

     

    Regards,

    Mohit Bansal