Forum Discussion
Hi ssteinhorst,
There is no build in easy way to validate on a certain value as long as it is NOT always present in the same node.
There are options however to dynamically assert this.
Easy option can be just to check whether the value exists in the response.
Either via the contains assertion:
Or via the JSONPath expression if you want to check specifically in a certain array, for instance:
Otherwise, if you want to check really that it exists only in the work_unit id element you will have to use groovy.
I think it should work something like this.
import com.eviware.soapui.support.JsonUtil def Records = context.expand('${yourtestcase#Response#$[\'Records\']}') //Records is now a string of all your items in the array def RecordsArray = JsonUtil.parseTrimmedText(Records ); //now it is convereted back to an arry def n = eigenschappenArray.size() //we count how many records items there are in the array for (i=0; i < n; i+= 1) //we create a for loop to go through all the elements of the array { def work_unit_id = context.expand ('${yourtestcase#Response#$[\'Records\']['+i+']['\work_unit\'][\'0\'][\'id\']}') if (work_unit_id == "kdkd9df980sdkdn2") {log.info ("work_unit id is found in node "+i)} }
As a follow up, in the script posted how does that assert in a soap ui test? Would you run that script as a test step then assert on the 'work_unit id is found in node' text?
And thanks! That is really helpful!
I did end up using a script assert which seems to have solved my problems. The assert looks like this:
def json = new groovy.json.JsonSlurper().parseText(context.response)
assert json.Records.work_unit.id.contains('RecordsIdValue')
Related Content
- 5 years ago
- 7 years ago
- 10 years ago
- 3 years ago
Recent Discussions
- 3 hours ago
- 17 days ago