Forum Discussion

_ivanovich_'s avatar
_ivanovich_
Frequent Contributor
9 years ago

How to assert data from the response

Hi,

 

when i send a request, i want to assert some data in the response using "contains assertion"

 

my response is:

 

"data": {
  "ci_status_id": "023f8f0e-fc53-42ec-8348-24a5470b7d7b",
  "ci_name": "John",
  "updated_by": null,

   "created_at": "2016-02-15T13:53:20Z",
  "id": "6b54b04d-7d59-44bc-8f54-f439eebf5d1c"
},
"success": true
}

I want to assert :

ci_status_id  = this value is static

ci_status_name = this value is static

update_by =  this value is static

created_at = this value is current datetime

id = this value is dynamic and change for each request

 

What is did:

i added a datacource "values" and a datasource loop

in datasource i added a colum named "data"

in data, i added the content od data retrieved from the response

In my request, i added "contains assertion"  and added this line ${values#data}

 

Problem:

the request is successfull but the assertion is not good because "created_at" is false,

this value is dynamic.

So how can resole this problem

or i can ignore the value of created_at

 

Thank you

3 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    It is not mentioned how the actual data is compared against the expected data.

    In case of created_at, you can create a date before sending the request and the data from response should be greater than the date collected at the time of sending request.
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Davy,

     

    I think that you need to work with each property separately – data.ci_status_id, ci_name, etc.