Forum Discussion
nmrao
10 years agoCommunity Hero
Thank 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)?
CoreBit
10 years agoNew Contributor
Hi Rao,
for instance, I would like to access the lastUpdateDate field like this:
$.response.data[?(@.label=='${#TestSuite#Property_Name}')].lastUpdateDateBut 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
- nmrao10 years agoCommunity Hero
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.
- CoreBit10 years agoNew ContributorHi Rao,
I was hoping it could be done with a transfer step... property expansion like this used to work in earlier soapUI versions for XPath... unfortunatelly it is not possible with JSONPath. This would be a feature request for future releases. ;)
The Groovy script test step was my plan B. Thank you for saving me some time by providing the code snippet!
Regards,
Adam