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!!
Right-click on Project and click on New Dictionary Variable. The Name by default in the screen is &{} and it has Value and Columns option. We will enter the Name and the Values to be used in the test case. We will change the test case to take the dictionary values.
Enter the argument to be used with the keyword. Go back to your test case. Now, you need to pass the value which is the URL to be used for the test case. In the test case, when you type the user-defined keyword and press Ctrl + Spacebar, it gives the details of the keyword along with the arguments.
There is no support in robot for getting the current keyword name. Since the code you're writing must be run from a keyword, your keyword should know what its own name is. If you write your keyword in python, the python library can also be a listener which can push and pop keywords on a stack.
This is because Run keyword And Continue On Failure does not return any value. It was never meant to. This keyword returns Boolean True if the keyword that is executed succeeds and False if it fails. ${passed} = Run Keyword And Return Status Should be Equal 1 2 Run Keyword Unless ${passed} Log The previous step FAILED!
Even though the code in the question still doesn't give the error you say it does because there are other errors that prevent it from running at all, the problem is this line:
${status} = ${resp.status_code}
That is not the proper way to assign variables. You must use the Set Variable keyword (or some of the other "Set" keywords) , like so:
${status}= Set Variable ${resp.status_code}
The reason you get the error you do is that every test or keyword step must have a keyword. You only have variable names and no keyword, so you get the error Keyword name cannot be empty.
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