I tried to Declare and Initialize a variable in Robot Framework using Selenium platform. But I'm getting an Error Keyword name cannot be empty.
I tried the following code
Integer:
*** Test Cases ***
Test Case 1
${item} ${0} # ${}
Boolean:
*** Test Cases ***
Test Case 2
${item} ${true} #${}
String:
*** Test Cases ***
Test Case 3
${item} Stackoverflow
Kindly assist me how to declare and initialize a variable within a Test Cases block in Robot Framework.
Reply for @Goralight
I'm getting an error
You need to use the Set Variable
Keyword to assign values to Variables outside the Variable Header:
*** Test Cases ***
Test Case 1
${item} Set Variable ${0} #${}
${item} Set Variable ${true} #${}
${item} Set Variable Stackoverflow
The above assigns the variable you have given in your test cases to the correct value. (This will overwrite ${item}
every time of course however) But this will assign the value, to the var ${item}
.
Read the Docs about it here
Any questions please ask :)
In my opinion, the following is a more readable way to do it:
*** Test Cases ***
Test Case 1
${item} = Set Variable ${0} #${}
${item} = Set Variable ${true} #${}
${item} = Set Variable Stackoverflow
You will get an error if you do the following:
${item} = Stackoverflow
The reason is that this assignment is expecting a keyword Stackoverflow
on right hand side.
Here is a working example of such assignment.
*** Test Cases ***
Test Case 1
${item} = Get My Value
Log ${item}
*** Keywords ***
Get My Value
${my text} = Set Variable Stackoverflow
[return] ${my text}
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