Skip to content

Take Screenshot doesn't process arguments correctly when run on failure #1356

Closed

Description

@tomekPawlak

Bug description
Take Screenshot doesn't process arguments correctly when it's registered to be run on failure. Normally when called explicitly it's working fine. Because of that as example unable to take fullPage screenshot.

Steps To Reproduce
Look at my 2 code snippets below:

Take Screenshot not working correctly when registered to run on failure
    [Setup]  New Page  https://www.yahoo.com/
    Browser.Register Keyword To Run On Failure  Take Screenshot  fullPage=True
    Click  //button[@name="agree"]
    Wait Until Network Is Idle
    Wait For Elements State  ddd  state=visible
    [Teardown]  Close Page
Take Screenshot working correctly when explicitly called
   [Setup]  New Page  https://www.yahoo.com/
    Click  //button[@name="agree"]
    Wait Until Network Is Idle
    Take Screenshot  fullPage=True
    [Teardown]  Close Page

Expected behavior
Take Screenshot should take full page screenshot for both examples.

Screenshots
Incorrect - screenshot taken from viewport as default. Notice that filename was taken from the argument fullPage=True
incorrect
incorrect_argument_as_filename

Correct - full page screenshot. File name correct according to default filename argument
correct
correct_filename

Desktop:

  • OS: Windows 10 / docker image rfbrowser-stable:v8.0.1
  • Browser Chrome
  • Version 94.0.4606.61

Additional context
Checked other KWs to be registered on failure with arguments like Log and they're working correctly.

Activity

  1. added
    bug
    on Sep 30, 2021
  2. aaltat commented on Sep 30, 2021

    @aaltat
    Member

    @all-contributors please add @tomekTieto for bugs

  3. allcontributors commented on Sep 30, 2021

    @allcontributors
    Contributor

    @aaltat

    I've put up a pull request to add @tomekTieto! 🎉

  4. aaltat commented on Oct 1, 2021

    @aaltat
    Member

    This is true, we do not do conversion, we just take arguments as they are, which in this case is plain strings and feed them forward. When we run keyword, we did expect that Robot Framework has done argument conversion and do not check any of the arguments.

    The problem is that if there is keyword which is not keyword from this library, we do know the arguments types and therefore we can not do argument conversion. But it might be possible to do argument conversion for keywords which are from this library.

    So there is two fixes:

    1. Do argument conversion for keywords which are ours.
    2. Document that only keywords from library has arguments converted automatically.
  5. aaltat commented on Oct 1, 2021

    @aaltat
    Member

    Reading the code also reveals nice bug in our code

                if is_same_keyword(self.run_on_failure_keyword["name"], "Take Screenshot"):
                    args = self.run_on_failure_keyword["args"]
                    path = args[0] if args else self._failure_screenshot_path()
                    self.take_screenshot(path)
    

    When Take Screenshot is run, code puts filename whatever was given as first argument. That is also wrong.

  6. aaltat commented on Oct 4, 2021

    @aaltat
    Member

    Even with that bug fixed we need to conversion for the arguments internally. Library relies on RF to the conversion when methods are run as keywords but for this usage case we need to do the conversion internally. Will look some RF api to do it, because argument conversion is pretty complex problem.

  7. aaltat commented on Oct 4, 2021

    @aaltat
    Member

    Had discussion with Pekka on Slack and this should work nicely:

    >>> from robot.running.arguments import PythonArgumentParser
    >>> def kw(a: int):
    ...     pass
    ... 
    >>> spec = PythonArgumentParser().parse(kw)
    >>> spec.resolve(['42'])
    ([42], [])
    >>> spec.resolve(['a=42'])
    ([], [('a', 42)])
    >>> spec.resolve(['oops'])
    Traceback (most recent call last):
    [snip]
    ValueError: Argument 'a' got value 'oops' that cannot be converted to integer.
    
  8. aaltat commented on Oct 6, 2021

    @aaltat
    Member

    Now Register Keyword To Run On Failure will return an object which contains keywords name and args. Instead of the old keyword name. That is BICWIC change.

  9. aaltat commented on Oct 7, 2021

    @aaltat
    Member

    @tomekTieto this is now fixed in main branch in the repository. Could you give it a try and see does it work like you expected?

  10. added this to the v9.0.0 milestone on Oct 13, 2021
  11. tomekPawlak commented on Oct 15, 2021

    @tomekPawlak
    Author

    Hello @aaltat now I'm experiencing an issue:
    [ WARN ] Keyword 'Take Screenshot ('fullPage', True)' could not be run on failure: 'tuple' object has no attribute 'upper'
    same with all possible arguments.
    Tested on my local Windows environment and on browser-docker image.

  12. aaltat commented on Oct 15, 2021

    @aaltat
    Member

    Could you run test with --loglevel trace set from command line and show full stack trace.

  13. tomekPawlak commented on Oct 15, 2021

    @tomekPawlak
    Author

    Added even a debug log but nothing special there regarding issue
    debug-20211015-124501.log

  14. aaltat commented on Oct 15, 2021

    @aaltat
    Member

    Ah, now I see. You have used named argument syntax, key=value and looks like we have a bug there.

  15. aaltat commented on Oct 15, 2021

    @aaltat
    Member
  16. tomekPawlak commented on Oct 15, 2021

    @tomekPawlak
    Author

    Yes, using positional arguments instead of named arguments is working fine

  17. aaltat commented on Oct 15, 2021

    @aaltat
    Member

    Lets move the discussion in #1396

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions