Hi! Using robot 6.0.2 and I declared a variable separated by underscores. I later used that variable but missed one underscore. Robot used the old variable regardless instead of throwing an error that the variable does not exist.
Is there a change in naming conventions for variables in relation to underscores?
Sample code snippet:
Check Something else
[Tags] tt2
${command_edited_2}= Set Variable Something wicked this way comes
Log ${command_edited_2}
Log ${command_edited2} # This has the same value as the previous variable
No changes in naming conventions. Underscores, spaces and case insensitive for variables names, are still the same.
In your example, Robot Framework always see the variable as, ${commandedited2}
.
Ah! thank you… I didn’t know about it. I thought like most programming languages, something like one_variable and oneVariable and onevariable would be all different identifiers.
Will need to remember that in the future
From the official RobotFramework User Guide:
Robot Framework variables, similarly as keywords, are case-insensitive, and also spaces and underscores are ignored. However, it is recommended to use capital letters with global variables (for example,
${PATH}
or${TWO WORDS}
) and small letters with local variables that are only available in certain test cases or user keywords (for example,${my var}
). Much more importantly, though, case should be used consistently.
To this I would like to add that in my personal experience, while Robot Framework ignores space and underscores in keyword and variables names, as well as lower and upper case, it sometimes leads to unexpected errors in the following cases:
-
in python expression evaluation: variables cannot have space (also see robotcode#244)
-
in keyword “named arguments”: case and space are strictly followed
-
when using the dot notation (to class attribute) the presence of space in the variable name is confusing.
-
two space are used to delimit tokens, so spaces are actually taken into account
Given this situation we decided to systematically use of underscores “_” instead of space in variables and arguments names. This can thankfully be enforced using robotidy RenameVariables transformer.
This does not reduce readability (on the contrary).
This does not apply to keywords, where space do not pose such an issue and using them makes reading the code nicer. (In practice using underscores in keywords raises a warning from robocop W0305)