Service Virtualization

 View Only
  • 1.  Sending XML Response in Rest Post Step

    Posted Jun 16, 2016 12:51 PM

    I have a test cases where i have a web service step. I am storing the response in a property.

    Now i am trying to update test management tool Rally with pass/failure using Rest Step and want to send the stored response however i keep getting parse error.

    I am assuming i will need to convert the response into string but cannot find any step for that either.

     

    Heres the generic flow

     

    1. Web Service Execution Step - Stored the response in property {{StepResponse}}

    2 Rest Step Connecting to Rally (Test management tool)

     

    {

    "TestCaseResult":

    {"TestCase":"/testcase/57521201028",

    "Build":"101",

    "Date":"{{Timestamp}}",

    "TestSet":"",

    "Notes":"{{StepResponse}}",

    "Verdict":"Fail"}

    }

     

    Here's the error i got

     

    {"CreateResult": {

        "Errors": ["Cannot parse input stream due to I/O error as JSON document: Parse error: expected '}' but saw '1' [ chars read = >>>{\"TestCaseResult\":{\"TestCase\":\"/testcase/57521201028\",\"Build\":\"101\",\"Date\":\"2016-06-16T11:22:24-0500\",\"TestSet\":\"\",\"Notes\":\"<?xml version=\"1<<< ]"],

        "_rallyAPIMinor": "0",

        "_rallyAPIMajor": "2",

        "Warnings": []

    }}



  • 2.  Re: Sending XML Response in Rest Post Step

    Posted Jun 16, 2016 01:19 PM

    use this til you get the json doc right..

    http://codebeautify.org/jsonvalidate

     

    the problem is the " inside the xml document.  I might change these to &quot;



  • 3.  Re: Sending XML Response in Rest Post Step

    Posted Jun 16, 2016 01:32 PM

    Thanks for response but the issue is not with json document but how can i sent the captured response in rest post. I need to send the error as it is for reporting ........



  • 4.  Re: Sending XML Response in Rest Post Step

    Posted Jun 16, 2016 02:35 PM

    the problem is you are getting a parse error on the json with the xml embedded.. it is STILL a JSON document

     

     

    {

    "TestCaseResult":

    {"TestCase":"/testcase/57521201028",

    "Build":"101",

    "Date":"today",

    "TestSet":"",

    "Notes":"<xml value="1"",

    "Verdict":"Fail"}

    }

     

    notice the ="1"", the extra double quotes will cause a parse problem..

    which is what the error said

     

    "Errors": ["Cannot parse input stream due to I/O error as JSON document: Parse error: expected '}' but saw '1' [ chars read = >>>{\"TestCaseResult\":{\"TestCase\":\"/testcase/57521201028\",\"Build\":\"101\",\"Date\":\"2016-06-16T11:22:24-0500\",\"TestSet\":\"\",\"Notes\":\"<?xml version=\"1



  • 5.  Re: Sending XML Response in Rest Post Step

    Posted Jun 16, 2016 02:37 PM

    so how can i convert it to string. is there an existing step or do i need to write custom step ........



  • 6.  Re: Sending XML Response in Rest Post Step

    Broadcom Employee
    Posted Jun 16, 2016 03:58 PM

    You could Base64 encode StepResponse & using the encoded value in your rest step



  • 7.  Re: Sending XML Response in Rest Post Step

    Posted Jun 16, 2016 04:16 PM

    yeh, depends on what the receiver of the message is going to do with that content



  • 8.  Re: Sending XML Response in Rest Post Step
    Best Answer

    Broadcom Employee
    Posted Jun 17, 2016 08:03 AM

    Try using the following payload

     

    {

    "TestCaseResult":

    {"TestCase":"/testcase/57521201028",

    "Build":"101",

    "Date":"{{Timestamp}}",

    "TestSet":"",

    "Notes":"{{=StepResponse.replace("\"","\\\"")}}",

    "Verdict":"Fail"}

    }



  • 9.  Re: Sending XML Response in Rest Post Step

    Posted Jun 17, 2016 10:51 AM

    Thanks for the reply. It partially worked i am still tweaking to get the complete response.



  • 10.  Re: Sending XML Response in Rest Post Step

    Posted Jun 17, 2016 12:56 PM

    Thanks i was able to send the entire message by replacing few more tags