Forum Discussion
9 Replies
- TanyaYatskovskaSmartBear Alumni (Retired)
Hi sumeetb,
I suppose that you selected the ID node - that's why you receive the data only for one element. You need to select a parent node of IDs. According to your code, it should be either summary or test. Does it help?
- nmraoChampion Level 3Show the raw response, please?
- sumeetbOccasional Contributor
Please see json response below.
{
"summary": [{
"id": "26590924327313990",
"name": "Summary-1",
"state": "ACTIVE",
"runTimestamp": 1473138585467,
"scheduledTimestamp": 1473138585507,
"createdTimestamp": 1473138585507,
"test": [{
"id": "15473842955298105",
"name": "test-1",
"createdTimestamp": 1473138585467,
"runTimestamp": 1473138585467,
"status": {
"Pass": 10,
"Fail": 20
}
}]
},
{
"id": "30493603067815445",
"name": "Summary-2",
"state": "ACTIVE",
"runTimestamp": 1473138254517,
"scheduledTimestamp": 1473138254520,
"createdTimestamp": 1473138254520,
"test": [{
"id": "6780837264054677",
"name": "Test -2 ",
"createdTimestamp": 1473138254517,
"runTimestamp": 1473138254517,
"status": {
"Pass": 1,
"Fail": 2
}
}]
}]
}I need to extract all ids of summary.test.id
i checked with summary.test still not able to get values. its returning zero rows.
- nmraoChampion Level 3
Here is the groovy script:
import groovy.json.JsonSlurper def response = '''{ "summary":[ { "id":"26590924327313990", "name":"Summary-1", "state":"ACTIVE", "runTimestamp":1473138585467, "scheduledTimestamp":1473138585507, "createdTimestamp":1473138585507, "test":[ { "id":"15473842955298105", "name":"test-1", "createdTimestamp":1473138585467, "runTimestamp":1473138585467, "status":{ "Pass":10, "Fail":20 } } ] }, { "id":"30493603067815445", "name":"Summary-2", "state":"ACTIVE", "runTimestamp":1473138254517, "scheduledTimestamp":1473138254520, "createdTimestamp":1473138254520, "test":[ { "id":"6780837264054677", "name":"Test -2 ", "createdTimestamp":1473138254517, "runTimestamp":1473138254517, "status":{ "Pass":1, "Fail":2 } } ] } ] }''' def summary = new JsonSlurper().parseText(response).summary def expectedIds = [15473842955298105, 6780837264054677] def actualIds = [] summary.each { summaryItem -> summaryItem.test.each { testItem -> actualIds << testItem.id } } log.info actualIds assert actualIds.sort() == expectedIds.sort(), "Test Ids are not matching"
Related Content
Recent Discussions
- 22 hours agodipsthorat
- 2 days agoisbiat
- 3 days agoarmygrad