Forum Discussion
nmrao
10 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.
CoreBit
10 years agoNew Contributor
Hi 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
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