Forum Discussion
nmrao
Champion Level 3
Is it possible for you to post the raw response?
CoreBit
9 years agoNew Contributor
Hi Rao,
the response looks like this (shortened):
{ "response" : { "endRow" : 300, "totalRows" : 21938, "status" : 0, "startRow" : 0, "data" : [{ "label" : "Property_Value", "lastUpdateDate" : "2014-08-13T15:48:56" }, { "label" : "Property_Value2", "lastUpdateDate" : "2014-08-13T15:48:58" }, { "label" : "Property_Value3", "lastUpdateDate" : "2014-08-13T15:49:01" } ] } }
Regards,
Adam
- nmrao9 years agoChampion Level 3Thank you for the info. Here there are 3 labels (arraylist) which one's value you want to compare against Test suite's property? or to be matched with any one of the three(not any particular label)?
- CoreBit9 years agoNew Contributor
Hi Rao,
for instance, I would like to access the lastUpdateDate field like this:
$.response.data[?(@.label=='${#TestSuite#Property_Name}')].lastUpdateDate
But this does not work, I get the followin error message:
Thu Dec 10 14:11:04 CET 2015 lastUpdateDate [Array index [Ljava.lang.String;@1d2eca2 not found in path]
Though this works:
$.response.data[?(@.label=='Property_Value')].lastUpdateDate
EDIT:
Result in latter case will be:
[2014-08-13T15:48:56]
Any idea?
Regards,
Adam
- nmrao9 years agoChampion Level 3
I am not sure how to do it in property transfer using condition.
However, you can use groovy step[property tranfer becomes obselete if you use groovy step] to do the same (if you are ok?):
/* this script reads a json and gets the lastUpdateDate where label is * matching with test suite property called 'Property_Name' */ import net.sf.json.groovy.JsonSlurper //Using static json, you can use dynamic response as well def jsonText = '''{ "response" : { "endRow" : 300, "totalRows" : 21938, "status" : 0, "startRow" : 0, "data" : [ { "label" : "Property_Value", "lastUpdateDate" : "2014-08-13T15:48:56" }, { "label" : "Property_Value2", "lastUpdateDate" : "2014-08-13T15:48:58" }, { "label" : "Property_Value3", "lastUpdateDate" : "2014-08-13T15:49:01" } ] } }''' def response = new JsonSlurper().parseText(jsonText).response def dateNeeded = response.data.find{it.label==context.testCase.testSuite.properties['Property_Name'].value}.lastUpdateDate //setting the required date in 'DATE_FROM_PREVIOUS_RESPONSE' test case property and use it later steps like ${#TestCase#DATE_FROM_PREVIOUS_RESPONSE} context.testCase.setPropertyValue('DATE_FROM_PREVIOUS_RESPONSE', dateNeeded)
If you want to use dynamic response from previous request step, replace following in the above snippet
from:
def jsonText = '''{ "response" : { "endRow" : 300, "totalRows" : 21938, "status" : 0, "startRow" : 0, "data" : [ { "label" : "Property_Value", "lastUpdateDate" : "2014-08-13T15:48:56" }, { "label" : "Property_Value2", "lastUpdateDate" : "2014-08-13T15:48:58" }, { "label" : "Property_Value3", "lastUpdateDate" : "2014-08-13T15:49:01" } ] } }'''
to
//Replace the step name below. def jsonText = context.testCase.testSteps['step1'].testRequest.response.responseContent
Hope this helps.
Related Content
Recent Discussions
- 4 days agoemoya