Search code examples
jsongetrobotframework

How can I send a GET request with json payload in the Robot Framework?


I've looked at RESTinstance and RequestsLibrary, but can't find a way to send a GET to the server with JSON as part of my request. I am grateful for any advice.


Solution

  • Using the Get Request keyword from the RequestLibrary it could be done like below. A JSON in general is a dictionary in Robot Framework. In the example below the &{JSON} variable is equivalent with the following JSON:

    {
      "name": "peter",
      "other_attribute": "value"
    }
    

    With additional keywords you could create nested structures as well.


    Example:

    *** Settings ***
    Library           RequestsLibrary
    
    *** Variables ***
    &{JSON}    name=peter    other_attribute=value
    
    *** Test Cases ***
    Test
        Create session    alias=my_session    url=http://127.0.0.1:5000
        ${response}=    Get Request    alias=my_session    uri=api/your_api_endpoint    json=${JSON}
        Log    ${response}