recent posts

How to evaluate JSON in Robot Framework

Here is a simple example that will demonstrate how to evaluate JSON in Robot Framework. This can be useful if you are attempting to do some form of API testing that requires you to assert return values.

In our robot file, we will create a JSON variable, and utilize Python's built-in json loader to retrieve the data. Once we get the JSON loaded, we can use the "password" key to verify the expected value. I've added color coding to help show you what parts are matching.

*** Variables ***

${js string}=    {

...                  "random": {
...                       "passwd_change_date": "2016-12-16T11:26:26",
...                       "passwd_fail_count": 0,
...                       "password": "123456789",
...                       "status": 0,
...                       "user_name": "test@test.com"
...                  }
...              }


*** Test cases ***
TC
    &{data}=    Evaluate     json.loads($js_string)    json
    &{data}=    Set variable    &{data}[random]

    Should be equal    &{data}[password]    123456789

Source Reference:
How to evaluate JSON in Robot Framework How to evaluate JSON in Robot Framework Reviewed by JJ The Engineer on 5:41 PM Rating: 5

3 comments:

  1. I'm dazzled, I should say. Only sometimes do I go over a blog that is both educative and intriguing, and doubtlessly, you have nailed it. The issue is an issue that insufficient people are talking cleverly about. Presently i'm upbeat I unearthed this during my chase for something with respect to this. best interiors

    ReplyDelete
  2. This post is so useful and informative. Keep updating with more information.....
    IELTS Certification
    IELTS Coaching

    ReplyDelete

Powered by Blogger.