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
Advertisement
Answer
I think you should store UUID as a variable, and change your locator from your response.
response.getBody().jsonPath().get("events."+yourUUID+".status");