0

I have a Test Case where i have to compare Rest API response with DB result. Steps i have automated are - 1. POST a request 2. Get the API response 3. Compare with DB result

After posting a request to API, when i try to evaluate it, i am getting below error -

failed: TypeError: Expression must be string, got dictionary.
create session  session  ${apiurl}  disable_warnings=1
    &{headers}=    Create Dictionary    Content-Type=application/json  x-api-key=${api_token_key}
    ${api_response}=    post request  session    ${emp_id}/${module_name}  data=${request_body}
    ...  headers=${headers}
${response_list}=  evaluate  ${api_response.json()}
log to console  ${response_list}

Getting above error.

I am expecting below API response to be compared with the DB result.

 "page": {
    "size": 5,
    "totalElements": 278,
    "totalPages": 56,
    "number": 0
  },
  "embedded": {
    "emp": [
      {
        "id": 1,
        "bookid": 2,
        "batchid": "2018-aaa",
        "title": "ash",
        "sub1": 10,
        "sub2": 11,
        "sub failed": {
          "total": {
            "value": 50,
            "subject": "sub6",
            "filter": "[{"field":"1","exclusive":false,"operator":"IN","value":"2018-aaa"}]"
          }
        },
        "sports": {
          "total": {
            "value": 12,
            "subject": "PE",
            "filter": "[{"field":"1","exclusive":false,"operator":"IN","value":"2018-aaa"}]"
          }
        },
        "count": 222,
        "count1": 333,
        "improved": 0,
        "last": "2019-08-12",
        "isstudent": true
      },

How to compare the above API response with DB result

2
  • what's is your Json body format type while u posting to the server? string or dictionary? Commented Aug 13, 2019 at 8:11
  • Dictionary is posted to Server Commented Aug 13, 2019 at 8:34

1 Answer 1

2

just change your param data to json because if you use data it's for only Json string type.

create session  session  ${apiurl}  disable_warnings=1
    &{headers}=    Create Dictionary    Content-Type=application/json  x-api-key=${api_token_key}
    ${api_response}=    post request  session    ${emp_id}/${module_name}  json=${request_body}
    ...  headers=${headers}
${response_list}=  evaluate  ${api_response.json()}
log to console  ${response_list}
Sign up to request clarification or add additional context in comments.

3 Comments

But it still returns json and how to loop over the json response and compare with DB result
I think it's another question
@vectyvec how do u try to compare the result to db? you should share your code and your error

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.