I am creating a smoke test suite for a series of APIs using the RobotFramework and the RobotRequestsLibrary. This is my first time using the RobotFramework. In trying to clean up the code and make it more maintainable I decided to try using Keywords to remove all incidental details.
For example, here are two tests that I want to clean up:
*** Variables ***
${sint} http://int.somecoolwebsite.com
*** Test Cases ***
Retrieve Store Info By Code Should Return Successful
[Tags] get
Create Session data-int ${sint}
${resp}= Get Request int /store/1234
Should Be Equal As Strings ${resp.status_code} 200
Retrieve All Store Info Should Return Successful
[Tags] get
Create Session data-int ${sint}
${resp}= Get Request int /stores
Should Be Equal As Strings ${resp.status_code} 200
And my attempt at using Keywords:
*** Variables ***
${sint} http://int.somecoolwebsite.com
*** Keywords ***
Make ${call} Call To ${end_point}
Create Session ${sint} ${sint}
${resp} = Get Request ${sint} ${end_point}
${status} = ${resp.status_code}
Set Test Variable ${status}
Status Should Be ${required_status}
Should Be Equal ${status} ${required_status}
*** Test Cases ***
Retrieve Store Info By Code Should Return Successful
[Tags] get
Make Get Call To /store/1234
Status Should Be 200
Retrieve All Store Info Should Return Successful
[Tags] get
Make Get Call To /stores
Status Should Be 200
When I run the test cases with the Keywords I get the following error:
Keyword name cannot be empty.
I tried to Debug the issue and put a break point in the Keyword assignment and I notice that ${resp}
gets assigned and ${resp.status_code}
also works. But when I try to assign {$status}= ${resp.status_code}
the error is thrown.
I tried varies ways to reassign the variable using the builtin Set Variable but did not have any luck. Can you not assign variables in this way in Keywords? Any insight will be helpful. Thanks!!
Set Variable
declaration when writing in the code here. Without that, it does give an error. But in test cases I do not need to use that declaration. – Bloodcurdling