I'm currently using Robot Framework to automate some tests.
Problem: I am trying to figure out a way to make variables imported from 'Import Variables' keyword globally available (--variablefile is not an option for me right now, sadly).
I already tried some workarounds, with no luck:
1. Import Variables
2. Get Variables available in current scope
3. Loop through each variable and get its key and value
4. Set each variable globally (using Set Global Variable)
The problem I faced in the above approach is that there are different types of data on my external file (scalar, lists, dicts), and therefore 'Set Global Variable' fails at some point when trying to set a dict. It complains about "Dictionary item 'no' does not contain '=' separator.".
I researched a bit and found that robot can't assign a dict type variable like this "Set Global Variable ${DICT_VAR} {"key1":"data1", "key2":"data2"}". Practical explanation can be found here robot-framework github tests.
Well, I'm thinking about building a small library to accomplish this and use it like: "Import Variables /path/to/variables.py scope=global", where the attribute scope could be one of the following: test, suite, global.
Well, that's my struggle, folks. Hopefully someone can help me with that. (:
EDIT: So, about not being able to use --variablefile option: Currently, I'm asking the user for some inputs at the beginning of test execution, and one of these inputs is a selection among existent external files. I know I could say to the user "Please provide --variablefile option with external file absolute path.", but I do not want that since it is less practical for the user.
[SOLVED] Conclusion: I realized that what I was trying to do was not meant to be done using robot. Robot is a tool to create and maintain tests, generate reports, etc. Managing many files with variables (and global variables) should be avoided in the .robot files. Then I came up with an external file (a python script) that just do all this dirty job of selecting files and setting global variables. At the end of this script I just call subprocess.run("robot", args) where args are all the parameters (-V, -v, -i, etc) that robot needs to begin the test execution. In the end I was able to actually use the --variablefile (-V) option in the external script.
from Variables import *work? - Sebastian Mendez--variablefileis not an option? It seems that you're going down a path that requires some considerable effort and I've not yet heard a good justification for it. If you're concerned that a fixed file lacks the flexibility, I'd point you to the Robot Framework Variable Function or Class that allows for dynamic creation of variables. - A. Kootstra