In Robot Framework user guide there is a section that describes how to pass variable files and also some possible variables if needed.
Example:pybot --variablefile taking_arguments.py:arg1:arg2
My question is can i use these possible variables arg1 and arg2 in the taking_arguments.py file afterwards and if i can then how?
Right now i have this:
pybot --variablefile taking_arguments.py:arg1:arg2
taking_arguments.py contents:
IP_PREFIX = arg1
But that results in
NameError: name 'arg1' is not defined
The only way to use variables in an argument file using the --variablefile filename.py:arg1:arg2
syntax is to have your variable file implement the function get_variables
. This function will be passed the arguments you specify on the command line, and must return a dictionary of variable names and values.
For example, consider the following variable file, named "variables.py":
def get_variables(arg1, arg2):
variables = {"argument 1": arg1,
"argument 2": arg2,
}
return variables
This file creates two robot variables, named ${argument 1}
and ${argument 2}
. The values for these variables will be the values of the arguments that were passed in. You might use this variable file like this:
pybot --variablefile variables.py:one:two ...
In this case, the strings "one" and "two" will be passed to get_variables
as the two arguments. These will then be associated with the two variables, resulting in ${argument 1}
being set to one
and ${argument 2}
being set to two
.
I haven't tried to pass initial values to variables in a variable file... So I am not sure if this is something possible...
I can offer an alternative...
You can define manually some variables with their values at the pybot command...
pybot -variablefile taking_arguments.py -v IP_PREFIX:arg1 -v Varibale:Value
If I am not mistaken these manually initiated variables have a higher priority than these in the variable file. So even if they are initiated in the variable file, the values passed with the -v option will be used in the testcase.
Hope this can help you!
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