I am learning robot-framework, API automation:
*** Settings ***
Library RequestsLibrary
Library Collections
Library String
*** Variables ***
${headers} Create Dictionary Authorization Bearer abcde
*** Test Cases ***
Make a simple REST API call
[Tags] API
Create Session my_json http://localhost:3000
Log ${headers}
${response} = Get Request my_json /posts headers=${headers}
Log ${response}
# Check the Response status
Should Be Equal As Strings ${response.status_code} 403
# ${response} = Get Request my_json /posts
${json} = Set Variable ${response.json()}
Log ${json}
Log len(${json})
Should Be Equal As Strings ${json['name']} rajesh
I am getting this error in log.html
Documentation: Send a GET request on the session object found using the given
aliasStart / End / Elapsed: 20181209 18:43:04.159 / 20181209 18:43:04.175 / 00:00:00.016 18:43:04.175 FAIL AttributeError: 'str' object has no attribute 'items'
I think only create dictionary object needs to be changed. You should pass key and value to it. Refer link BuildIn(create Dictionary)
*** Settings ***
Library RequestsLibrary
Library Collections
Library String
*** Variables ***
${headers} Create Dictionary Authorization=“Bearer abcde”
*** Test Cases ***
Make a simple REST API call
[Tags] API
Create Session my_json http://localhost:3000
Log ${headers}
${response} = Get Request my_json /posts headers=${headers}
Log ${response}
# Check the Response status
Should Be Equal As Strings ${response.status_code} 403
# ${response} = Get Request my_json /posts
${json} = Set Variable ${response.json()}
Log ${json}
Log len(${json})
Should Be Equal As Strings ${json['name']} rajesh
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With