recent posts

Testing JSON Endpoints With Robotframework

Below is an example robot file that you can use to experiment with endpoint testing. Responses are returned in JSON.


*** Settings ***
Documentation     Robot Framework JSON and REST Testing
...                        Author: JJ The Engineer
...                        We use a free 3rd party site to demo these tests.
...                        Credits: jsonplaceholder.typicode.com

Library           Collections
Library           HttpLibrary.HTTP
Library           DateTime
Library           String

*** Variables ***
#Breakdown of endpoint below: https://jsonplaceholder.typicode.com/users

${HOST}        jsonplaceholder.typicode.com
${SCHEME}      https
${ENDPOINT}    /users

*** Test Cases ***
Get Users Endpoint Should Be Successful

    Create Http Context      ${HOST}      ${SCHEME}
    GET     ${ENDPOINT}
    Response Status Code Should Equal   200

Validate JSON

    ${response_body} =  Get Response Body
    Should Be Valid Json    ${response_body}
    Log Json                ${response_body}

Validate Dictionary

    ${response_body} =  Get Response Body
    Log Json    ${response_body}
    ${dictionary} =     Evaluate    json.loads('''${response_body}''')  json
    Log Dictionary      ${dictionary}



Testing JSON Endpoints With Robotframework Testing JSON Endpoints With Robotframework Reviewed by JJ The Engineer on 11:14 AM Rating: 5

No comments:

Powered by Blogger.