In the test case file I am using Set Variable to update the ${token} but it’s not getting updated.
Get Basic API Test
${token1}= Run Keyword Get AuthToken #keyword to get auth-token and assign it
${token}= Set Variable ${token1}
Log ${token}
${response}= Call Get Request ${headers_dictionary} ${endpoint} ${query_string}
Log ${response}
Hey so I think what you have here is a misunderstanding of how RobotFramework handles the Variables section at runtime. When the test cases is loaded it is going to attempt to verify ${token} which at that point is not set yet.
So a couple of options would look like:
You could simply make your headers dictionary after you get your token:
Get Basic API Test
${token}= Run Keyword Get AuthToken #keyword to get auth-token and assign it
${headers_dictionary}= Create Dictionary Authorization=Bearer ${token} Content-Type=application/json
charset=UTF-8
${response}= Call Get Request ${headers_dictionary} ${endpoint} ${query_string}
Log ${response}
Create a helper keyword to create the headers dictionary for you:
*** Keywords ***
Generate Headers For APIs
${token}= Run Keyword Get AuthToken #keyword to get auth-token and assign it
${headers_dictionary}= Create Dictionary Authorization=Bearer ${token} Content-Type=application/json
charset=UTF-8
[Return] ${headers_dictionary}
*** Test Cases ***
Get Basic API Test
${headers_dictionary}= Generate Headers For APIs
${response}= Call Get Request ${headers_dictionary} ${endpoint} ${query_string}
Log ${response}
Thanks for this. Was not knowing Create Dictionary can be used in Zoomba package.
Yeah, with this gives better flexibility to create headers.
Closing the issue