Declaring a variable in Robot Framework
Introduction
The first way is to create global variables at the beginning of the .robot file
The second is to use Set Variable
In the *** Variables *** block
Remember that there must be more than one space between the = sign and the value being assigned.
*** Settings *** # make at least two spaces beetween Documentation Simple example using SeleniumLibrary. Library SeleniumLibrary *** Variables *** ${WEBSITE_URL} = www.aredel.com *** Test Cases *** Test case number one [documentation] Web url test [tags] web Log To Console ${WEBSITE_URL}
Inside the test case
*** Settings *** # make at least two spaces beetween Documentation Simple example using SeleniumLibrary. Library SeleniumLibrary *** Variables *** *** Test Cases *** Test case number one [documentation] Web url test [tags] web ${WEBSITE_URL} = Set Variable www.heihei.ru Log To Console ${WEBSITE_URL}
Set Suite Variable
To make a variable available to all tests in a suite, Set Suite Variable is used.
In the following example, the variable is set in the Setting Suite Var test case and is used in Using Suite Var
*** Test Cases *** Setting Suite Var Set Suite Variable ${ID} ${10} Using Suite Var Log To Console ${ID}
============================================================================== Setting Suite Var | PASS | ------------------------------------------------------------------------------ Using Suite Var 10 Using Suite Var | PASS |
& Dictionary
If you need to save a dictionary in a variable, you need to use &
*** Settings *** # make at least two spaces beetween Documentation Simple example using SeleniumLibrary. Library SeleniumLibrary *** Variables *** *** Test Cases *** Test case number one [documentation] Web url test [tags] web &{VARIABLE} = Some Keyword Log To Console ${VARIABLE}
Article author: Andrei Olegovich