Forum Discussion
Sharath
12 years agoOccasional Contributor
ankitaT wrote: For JSON format, instead of XPath, usage of jsonslurper is recommended.
An example to achieve this is as:
import groovy.json.JsonSlurper
def response = messageExchange.response.responseContent
def slurper = new JsonSlurper()
def json = slurper.parseText response
def ExpectedResultMessage = context.expand( '${#TestCase#ResultMessage}' ).toString()
log.info 'ExpectedResultMessage ' + ExpectedResultMessage
log.info 'json response ' + json."nsms.Response"."nsms.msg"
assert json."nsms.Response"."nsms.msg" == ExpectedResultMessage
Hope it helps.
Regards,
Ankita
Hi Ankita.. Let me give you the scenario and the steps I've tried to make things work.
Scenario: I should maintain a id throughout the test suite which contains 10 or more Test cases. The ID which I get on executing the first Test case, should be passed as a part of the endpoint for the next coming test cases, say wwww.google.com/{id}
I tried: Creating the test suite and test cases, then adding HTTP Test request test step for each test cases. And then, after the test case has finished executing, the response is written to a xml file by using a Groovy script as a test step. BTW both the request and response are in JSON format not in XML. After writing the response to a file, I use another script to read the response from the file, and parse the JSON content to get only the value I need. Then I added the parameter to the endpoint for the next Test step, say http://www.google.com/$id. However, this failed!
And I tried your code but its showing some error and it is "No property found:json"
Now, how to pass this value as a part of the next test step's endpoint?
Related Content
- 10 months ago
- 5 years ago
- 6 years ago
- 2 years ago
- 9 years ago
Recent Discussions
- 21 days ago