Forum Discussion
Lucian
Community Hero
You can use the script I wrote and then pass the resulted value into a property like:
testRunner.testCase.setPropertyValue( "ElementsCount", countElement.toString() )
That property can later be used in a groovy or directly in a request.
${#TestCase#ElementsCount}
JoostDG
7 years agoFrequent Contributor
Hi Lucian,
Yes, I thought of that solution also, but I found the answer: It just looks like I did not grasp fully the script you provided.
I just had to use the full response from "myrestrequest" and then define the jsonObject like :
import static com.jayway.jsonpath.JsonPath.parse
def response = context.expand( '${myrestrequest#Response}' )
def countElement( String json, String jsonPath ) {
return parse( json ).read( jsonPath ).size()
}
def jsonObject = response
log.info countElement( jsonObject, '$.hasData.*' )
Thanks for this!!
Related Content
- 6 years ago
Recent Discussions
- 9 hours ago
- 9 hours ago
- 9 hours ago
- 9 hours ago