Skip to content
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

Strip Given/When/Then prefix for keywords that start with a variable #4577

Open
allanlei opened this issue Dec 26, 2022 · 2 comments
Open

Strip Given/When/Then prefix for keywords that start with a variable #4577

allanlei opened this issue Dec 26, 2022 · 2 comments

Comments

@allanlei
Copy link

When using Given/When/Then/etc to match keywords that start with a variable ${...}, then Give/When/Then is captured into the variable value.

According to Ignoring Given/When/Then/And/But prefixes,

Prefixes Given, When, Then, And and But are dropped when matching keywords are searched, if no match with the full name is found

Is there a builtin method to reverse this logic such that it checks for the prefix-dropped version first?

*** Keywords ***
${url} is open
    Log To Console           Open "${url}"

${ele} is clicked
    Log To Console           Click "${ele}"

${ele} should be visible
    Log To Console           Is Visible "${ele}"


*** Variables ***
${url}          https://google.com
${btn_1}        xpath=//a/b/c
${modal_2}      xpath=//a/b/c


*** Test Cases ***
Valid Login
    Given ${url} is open
    When ${btn_1} is clicked
    Then ${modal_2} should be visible

Outputs

Open "Given https://google.com"
Click "When xpath=//a/b/c"
Is Visible "Then xpath=//a/b/c"

Wanted output

Open "https://google.com"
Click "xpath=//a/b/c"
Is Visible "xpath=//a/b/c"

I can get this behaviour by changing https://github.com/robotframework/robotframework/blob/master/src/robot/running/namespace.py#L292-L298 to

        runner = self._get_runner_from_suite_file(name)
        if not runner and '.' in name:
            runner = self._get_explicit_runner(name)
        if not runner:
            runner = self._get_bdd_style_runner(name)
        if not runner:
            runner = self._get_implicit_runner(name)
@pekkaklarck
Copy link
Member

There's PR #5096 implementing this functionality so let's include this issue into RF 7.1 scope. I won't have time to review the PR right now, but I return to it after RF 7.0.1 is out.

@pekkaklarck
Copy link
Member

There are some backwards incompatibility concerns due to behavior being changed. In my opinion risks are small enough so that this doesn't need to wait until a major version, but the change needs to be nevertheless be mentioned in release notes.

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