Skip to content

Keyword scope docs are misleading #3670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JessefSpecialisterren opened this issue Sep 15, 2020 · 2 comments
Closed

Keyword scope docs are misleading #3670

JessefSpecialisterren opened this issue Sep 15, 2020 · 2 comments

Comments

@JessefSpecialisterren
Copy link

Under https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#keyword-scopes, the docs state that the following rule is used when determining keyword priority:

1. Created as a user keyword in the same file where it is used. These keywords have the highest priority and they are always used, even if there are other keywords with the same name elsewhere.

Robot Framework does not actually behave likes this when it comes to resource files. Consider the following three files:

Resource1.robot:

*** Keywords ***
A
    Log  Resource1

Resource2.robot:

*** Keywords ***
A
    Log  Resource2

B
    A

TestSuite1.robot:

*** Settings ***
Resource  Resource1.robot
Resource  Resource2.robot

*** Test Cases ***
Test Case 1
    B

Attempting to run TestSuite1.robot will fail with the following message:

FAIL : Multiple keywords with name 'A' found. Give the full name of the keyword you want to use:
    Resource1.A
    Resource2.A

So keyword B uses keyword A, which is "[c]reated as a user keyword in the same file where it is used". According to the documentation, this should just work. Yet it doesn't.

Considering the way namespacing is actually implemented, I'd suggest updating this line of documentation by adding "test case":

1. Created as a user keyword in the same test case file where it is used. These keywords have the highest priority and they are always used, even if there are other keywords with the same name elsewhere.

You may also want to add something like:

Note
When a test case file defines a keyword, all uses of keywords with the same name in resource files will be overridden, unless they use the full name of the keyword as explained in the next section.

Also, I'd like to use this opportunity to thank you for creating such an awesome piece of software, maintaining and improving it through the years and letting us use it for free. Much, much, much appreciated 🙂!

@JessefSpecialisterren
Copy link
Author

I've been thinking some more on this, and maybe this would be a better replacement for the first keyword scope rule:

1. Created as a user keyword in the test case file that is currently being executed. These keywords have the highest priority and they are always used, even if there are other keywords with the same name elsewhere.

This better covers how Robot Framework seems to work. My knowledge is still limited, though, so correct me if I'm wrong 🙂

Also, even with this version of the scope rule, I'd still like to see the aforementioned Note added. Not knowing that test-case-file-defined keywords override uses in imported resource files can cause some very, very unexpected behavior 😇

@pekkaklarck
Copy link
Member

pekkaklarck commented Mar 3, 2021

True, the docs should mention that keywords in the same file as the test case have highest priority. I'll use this:

Created as a user keyword in the currently executed test case file. These keywords have the highest priority and they are always used, even if there are other keywords with the same name elsewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants