0

This is the response (sort of)

{
  "Cats": [
        {
        "Code": "XXXX",
        "Ven": {          
            "Description": "Any"
        },

        },
        "Rate": {
            "Actual": {
                "Amount": "XXX",
                "Currency": "USD"
            },
            "Token": "Cg..........................................",

       {
        "Code2": "2XXXX",
        "Vend": {
            "Code": "2X",
            "Description": "aNY2"
        },

            "Token": "Cg...................................",

}

I need to verify if the response contains the Token value and if this token value contains a certain string, this is the code

    Response responseshop = given().header("Authorization", "Basic 
    XXXXXXXXXXX=").header("accept-version","2.0.0").header("Accept", 
    "application/xml").
            param("Location", "Geocode,XX.XXXXXX,-XX.XXXXXX").
            param("Pick", "2017-12-12"). 
            param("Drop", "2017-12-15").            
            get("/cats/shop?AppKey=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); 
        responseshop.then().log().all().
            statusCode(200).            
                     body("root.Cats.Rate.Token", containsString("Cg")); 
            System.out.println("This is the Response");
            System.out.println(responseshop);             
            String Token =responseshop.path("root.Cats.Rate.Token");
           System.out.println("This is the Token");
           System.out.println(Token);

BTW the response is printed out and it passes also the 200 status verification, But Im getting this assertion error over and over again:

java.lang.AssertionError: 1 expectation failed.
XML path root.Cats.Rate.Token doesn't match.
Expected: a string containing "Cg"
Actual: 
Cg........................

Im new with restassured, am I missing something. Thanks!

PGS
  • 3
  • 2

1 Answers1

0

I think that the one of the problems is that you have a JSON response and want to check an xml content as in the header you set it in the "Accept" header as "application/xml". Try with "application/json" and check your jsonpath as well because it is also smelly.

If you cannot share the json of yours, you try to evaluate and find to correct jsonpath via http://jsonpath.com/ as if you can have multile record under the Cats array it should look like that for the first elem: "Cats[0]..Token"

Gergely A.
  • 404
  • 3
  • 6