Variable Declaration and Initialization in Robot Framework within a Test Cases block

B.Balamanigandan picture B.Balamanigandan · Jun 26, 2017 · Viewed 30.1k times · Source

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

enter image description here

Answer

Goralight picture Goralight · Jun 26, 2017

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 :)