Reputation: 1320
I want to get the value of status
from my response. So that i can assert it. I'm using rest assured with java & serenity BDD.
Response
{
"locationType": "STORE",
"locationId": "0003",
"events": {
"66e326db-fbfb-4f6e-9d2b-9425e7test5": {
"status": "BOOKING_OPEN"
}
}
}
So, here the event id (66e326db-fbfb-4f6e-9d2b-9425e7test5)
is dynamic, which means for each run this UUID will get change.
Code
Response response = SerenityRest.lastResponse();
final ValidatableResponse validatableResponse = response.then();
validatableResponse.assertThat().body("events.*.status", containsString(expectedResponse));
When i run this, i'm getting Unrecognized Exception from serenity BDD. I think, that there is some issue in traversing in JSON.
Can someone please help me on getting the value of status here? So in this case, i'm looking for
BOOKING_OPEN
Upvotes: 1
Views: 935
Reputation: 12695
Groovy JsonSlurper does not support *
breadthFirst()
or **
depthFirst()
tokens.
You could use below one to get the String result:
response.getBody().jsonPath().get("events.collect{it.value.status}.find()");
// would return "BOOKING_OPEN"
or below one to get a List result:
response.getBody().jsonPath().get("events.collect{it.value.status}");
//would return ["BOOKING_OPEN"]
Upvotes: 0
Reputation: 71
I think you should store UUID as a variable, and change your locator from your response.
response.getBody().jsonPath().get("events."+yourUUID+".status");
Upvotes: 1