0

I'm trying to validate that a JSON array contains a certain value. Using Rest-Assured with a hamcrest matchers import in Java. This is the JSON that I'm validating;

{
    "graph": {
        "groupedResultColumns": [
            "Task_Status",
            "Task_TimeSpent"
        ]
    }
}

After reading about rest assured and hamcrest matchers, this is the code that I am trying at the moment;

{
    SerenityRest.then()
      .body(containsString("groupedResultColumns"))
      .assertThat().body("groupedResultColumns", (hasItems("Task_TimeSpent")));
}

This is the error I'm getting;

JSON path groupedResultColumns doesn't match.
Expected: (a collection containing "Task_TimeSpent")
  Actual: null

Any help or advice is appreciated, Thanks!

1
  • 1
    I don't know about SerenityRest but... are you sure that groupedResultColumns is selected? Maybe you should select graph first? Commented Sep 30, 2019 at 15:02

1 Answer 1

1

You need to specify the json path to the collection. The "groupedResultColumns" is inside "graph" so your path to the body would be graph.groupedResultColumns.

Your code would be something like this:

{
    SerenityRest.then()
      .body(containsString("groupedResultColumns"))
      .assertThat().body("graph.groupedResultColumns", (hasItems("Task_TimeSpent")));
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.