Kenandrae
Kenandrae

Reputation: 15

Assertion for Xml in Rest Assured

I finally figured out how to get the List out of the XML. The Rest Assured site however didn't go over how to make a assertion for the list I got. How do I assert This movie has bruce willis as a actor with the rest assured format of given, when, then? Do I use the List in the given()?

@Test
public void verifyBruceWillisIsInDieHard() {
    String xmlPath = get(
            "http://www.omdbapi.com/?t=Die+Hard&y=&plot=short&r=xml")
            .andReturn().body().asString();
    XmlPath actor = new XmlPath(xmlPath);
    actor.setRoot("movie");
    List<String> nameOfFirstActor = actor.getList("movie.@actors");
    System.out.println(nameOfFirstActor);

Upvotes: 0

Views: 1772

Answers (2)

Kenandrae
Kenandrae

Reputation: 15

With a little tweaking to your answer this worked.

 when().
       get("http://www.omdbapi.com/?t=Die+Hard&y=&plot=short&r=xml").
then().
       body("root.movie.@actors", containsString("Bruce Willis"));

Upvotes: 1

Johan
Johan

Reputation: 40510

Something like this perhaps?

when().
       get("http://www.omdbapi.com/?t=Die+Hard&y=&plot=short&r=xml").
then().
       body("movie.@actors", hasItem("bruce willis"));

Upvotes: 1

Related Questions