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

Return value of Register keyword to run on failure cannot always be used to restore original state #176

Closed
stevejefferies opened this issue Mar 4, 2013 · 8 comments

Comments

@stevejefferies
Copy link
Contributor

There seems to be an issue with the implementation of the "Register keyword to run on failure" keyword. The keyword returns the value of the previously registered keyword which works fine if this is set to a keyword e.g. "Capture Page Screenshot" but if the registered keyword is set to "None" the return value is the string "No keyword". If you then try to use the return value "No keyword" and pass this back into "Register keyword to run on failure" a warning is generated:

"Keyword 'No keyword' could not be run on failure: No keyword with name 'No keyword' found."

I guess this keyword should either be returning "Nothing" as a string rather than "No keyword" to be consistent with the current way of disabling the run-on-failure functionality or it could return None instead

Example test case (simplistic example):

*** Settings ***
Library           Selenium2Library

*** Test Cases ***
Test Case 1
    ${previous_kw}=    Register Keyword To Run On Failure    Nothing
    ${previous_kw}=    Register Keyword To Run On Failure    Capture Page Screenshot
    Register Keyword To Run On Failure    ${previous_kw}
    Open Browser    http://www.google.com
    Page Should Contain    invalid_string

The implementation could be changed to the following which would return None from line 2 of the above test case and no warnings are observed on failure:

def register_keyword_to_run_on_failure(self, keyword):
    """Documentation here....
    """
    old_keyword = self._run_on_failure_keyword
    old_keyword_text = old_keyword if old_keyword is not None else "No keyword"

    if keyword:
        new_keyword = keyword if keyword.strip().lower() != "nothing" else None
    else:
        new_keyword = None
    new_keyword_text = new_keyword if new_keyword is not None else "No     keyword"

    self._run_on_failure_keyword = new_keyword
    self._info('%s will be run on failure.' % new_keyword_text)

    return old_keyword
@ombre42
Copy link
Contributor

ombre42 commented Oct 5, 2014

I think that changing the return value is an unnecessary and a riskier change. When this was first implemented, it should have returned "nothing", but it seems too late to change that. If we consider "No keyword" and "nothing" to be synonymous, the warning will go away.

@zephraph zephraph modified the milestones: Future Release, 1.9 Apr 24, 2015
@boakley
Copy link
Contributor

boakley commented Dec 7, 2015

I just stumbled on this today. This really ought to be fixed. I shouldn't have to add special case code in my test when saving and restoring the keyword. If changing the return value is unacceptable, perhaps changing it so that passing in "No Keyword" has the same effect as passing in "Nothing".

I shouldn't have to have special case code in my tests and keywords in case there is no keyword registered. In other words, the following should always return the system to the correct state:

| | ${old}=  | Register keyword to run on failure  | Nothing
| | Register keyword to run on failure  | ${old}

@aaltat
Copy link
Contributor

aaltat commented Dec 8, 2015

Ugh

I agree, would you like to make a pull requests to fix it?

-Tatu

-----Original Message-----
From: "Bryan Oakley" notifications@github.com
Sent: ‎07/‎12/‎2015 18:44
To: "robotframework/Selenium2Library" Selenium2Library@noreply.github.com
Subject: Re: [Selenium2Library] "Register keyword to run on failure" shouldnot return the string "No keyword" (#176)

I just stumbled on this today. This really ought to be fixed. I shouldn't have to add special case code in my test when saving and restoring the keyword. If changing the return value is unacceptable, perhaps changing it so that passing in "No Keyword" has the same effect as passing in "Nothing".
I shouldn't have to have special case code in my tests and keywords in case there is no keyword registered. In other words, the following should always return the system to the correct state:
| | ${old}= | Register keyword to run on failure | Nothing
| | Register keyword to run on failure | ${old}

Reply to this email directly or view it on GitHub.

@aaltat
Copy link
Contributor

aaltat commented Dec 29, 2015

Perhaps easy fix could be change the No Keyword to No Operation?

@aaltat
Copy link
Contributor

aaltat commented Aug 30, 2017

This should have deprecated this in 3.0 Alpha release. We will make at least one release candidate, perhaps deprecation could be done in there. Adding this to 3.0.0 milestone.

@aaltat aaltat modified the milestones: v3.0, Future Release Aug 30, 2017
@aaltat
Copy link
Contributor

aaltat commented Sep 2, 2017

We are not going to deprecate the old functionality, instead we are going to change the functionality.

pekkaklarck added a commit to pekkaklarck/SeleniumLibrary that referenced this issue Sep 2, 2017
1. Return value from `Register keyword to run on failure` can now
   always be used as an argument to the keyword. In practice the
   keyword nowadays returns `None` if the functionality was disabled
   and `None` (as well as `'NONE'`) can be used to disable the
   functionality. Fixes robotframework#176.

2. Moved the hook method to run when a keyword fails to the core.
   This simplifies implementation. The hook method was also
   renamed from `run_on_failure` to `failure_occurred`.
@pekkaklarck pekkaklarck mentioned this issue Sep 2, 2017
@pekkaklarck
Copy link
Member

My changes in #884 change the behavior like this:

  • In addition to the previously supported string 'Nothing' It's possible to use string 'NONE' (case-insensitively) as well as None and anything else considered false in Python to disable the run-on-failure functionality.

  • The keyword returns None if the functionality was previously disabled.

The change is to some extend backwards incompatible, because the earlier 'No keyword' return value is now None. I doubt this causes too big problems in practice and consider it safe enough in a major release. Please comment here if you feel otherwise!

@pekkaklarck pekkaklarck changed the title "Register keyword to run on failure" should not return the string "No keyword" Return value of Register keyword to run on failure cannot always be used to restore original state Sep 2, 2017
@aaltat aaltat closed this as completed in fa1fee3 Sep 4, 2017
@pekkaklarck pekkaklarck added beta 3 and removed rc 1 labels Sep 28, 2017
@pekkaklarck
Copy link
Member

On a second though I don't think it is useful to support any value considered false on Python when disabling this functionality. Supporting just None, including strings NONE and NOTHING ought to be enough (and easier to document).

pekkaklarck added a commit to pekkaklarck/SeleniumLibrary that referenced this issue Nov 5, 2017
Also changed disabling this functionality not to work with any false
value. That's related to robotframework#176.
aaltat pushed a commit that referenced this issue Nov 8, 2017
Also changed disabling this functionality not to work with any false
value. That's related to #176.
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

6 participants