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!

Ethranes
  • 329
  • 1
  • 5
  • 22
  • 1
    I don't know about SerenityRest but... are you sure that groupedResultColumns is selected? Maybe you should select graph first? – Starbax Sep 30 '19 at 15:02

1 Answers1

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")));
}