Hi,
I am using the robotCode extension.
In my project, I have a common.resource and I have the test.robot
In test.robot, I am calling the common.resource with some variables.
In test.robot file I am using those variables but in VSCode robotCode raises an error as variables are not found.
In the previous extension as RobotFramework Language Server, it is not assigned an error, but with RobotCode it is.
Do you have any suggestion how should I handle this error? Where should I pass those variables from common.resource to test.robot file ?
Or do you have other idea, how should I define the variables in my project?
Error : Variable â${abc}â not found.robotcode(VariableNotFound)
Thanks Project: common.resource
*** Keywords ***
Setup Environment
${RANDOM_VALUE} Generate Random Value
Set Suite Variable ${abc} ${RANDOM_VALUE}
Set Suite Variable ${def} def_${RANDOM_VALUE}
In test.robot file
*** Settings ***
Resource common.resource
*** Test Cases ***
TC:01 - Verify Test
Set Test Variable ${reservation_id} 166198
Verify Response ${abc} ${def}
Note:
even for the Set Suite Variable definition, I am getting the not found error Set Test Variable ${string} 166198
Variable â${string}â not found.robotcode(VariableNotFound)
*** Keywords ***
Setup Environment
${RANDOM_VALUE} Generate Random Value
Set Suite Variable ${abc} ${RANDOM_VALUE}
Set Suite Variable ${def} ${RANDOM_VALUE}
test.robot
*** Settings ***
Resource common.resource
Test Setup Setup Test
*** Test Cases ***
TC:01 - Verify Test
Set Test Variable ${reservation_id} 166198
Verify Response ${abc} ${def}
*** Keywords ***
Setup Test
common.Setup Environment
How do people handle those kinds of issues?
What are the best practices for using random data which comes from the common place or external resource, in tests ?
We are Software Testers, and the tools we use , most of the times are Open Source Software, which is the case for RobotCode. We must constantly question ourselves if the problem we are finding is from the tool we use, in this case the IDE.
I am the maintainer of RIDE, and this kind of error should not be reported, in the sense that variable autocompletion would not know about the ${abc} variable. We have to understand that these IDEs cannot do such advanced inspection of the code to find all the referenced objects. Well, maybe they can, but the effort to program this is too big.
In short, the free tools are here to help us and we must âguessâ their limitations.
The best thing that users can do, is to learn to code, and try to solve the problems they find in their favorite tools. This was my path, from Software Tester (which I still am) to maintainer of an IDE.
Best practice is to announce global/suite variables in *** Variables *** section of common.resource. That way you do not only get those variable-not-found-âissueâ solved, but you also tell every human user of that common.resource what variables to expect (supporting modularity and reusability)
Variables defined in a resource file, however, are accessible in all files that import the resource file directly or indirectly by imports of other resource files. This allows for the sharing of variables across multiple suites or files while maintaining modularity and reusability.
Long Story
The âlimitationâ is Robot Framework itself. RobotCode aims to make accurate analysis, where as other tools make a guess. The old Robot Framework LSP that you have mentioned did such guesses. Most of the time it was right, sometimes they werenât. You only knew for sure when code has been executed.
While RobotCode could probably implement a call analysis, it would slow down project analysis (and thus: autocompletion) tremendiously. And it would still not be accurate as there are many ways to intercept and exchange keyword calls. Thus variable completion would become undeterministic. As a result, the âerrorâ message would disappear in the IDE, but the variable completion would become inaccurate.
Imagine you have hundreds of keywords, shared across a huge project and the keywords make a lot of use of magic SUITE and GLOBAL variables. That is hard to maintain, regardless what IDE. Thatâs why announcing âglobalâ variables is a best practice for IDEs and maintainability:
*** Variables ***
${ABC} ${NONE} # unassigned SUITE variable
${DEF} ${NONE} # unassigned SUITE variable
*** Keywords ***
Setup Environment
${random_value} Generate Random Value
Set Suite Variable ${ABC} ${random_value} # assign SUITE variable
Set Suite Variable ${DEF} ${random_value} # assign SUITE variable
Although Robot Framework is case-insensitive, it is best practice to write variables with higher scope than LOCAL in capital case.