Forum Discussion
Thanks for the reply! I'm not sure what happened to mine but this is all very new to me. Should it look like this below:
def x = 0 def response = context.expand( '${GET/Nodes#Response#$[x][\'node\']}' ) def nodeId = context.expand( '${GET/Nodes#Response#$[x][\'id\']}' ) if (response != 'TestB'){ x++ } else{ testRunner.testCase.testSuite.setPropertyValue('nodeId', nodeId) }
How do I tell it that I want it to use the variable x as the index (response and nodeId lines). I get an error with the above example. Should I even add an index if I want to look at all of them?
Do I need to convert to string? Should I be using JsonSlurper to parse the Json first? Is there a wildcard I could use instead of an index that would achieve the same result with less code?
shales ,
If I understand you right, you want to extract the value of "id" field where it matches "node" value that you provide and then set its value at test case level.
Also understand you know all the stuff except getting id value.
Below line helps to achieve that.
//assign response, hope you know def response = //Extract id value def nodeValue = 'TestB' def id = new groovy.json.JsonSlurper().parseText(response).find {it.node == nodeValue}.id //Set Id value at test case level, hope you know