MarketSquare / robotframework-browser

Robot Framework Browser library powered by Playwright.
Apache License 2.0
526 stars 106 forks source link

Take screenshot filename argument failing when registered to be run on failure #1702

Closed tomekPawlak closed 11 months ago

tomekPawlak commented 2 years ago

Like agreed here #1396 reporting this.

Describe the bug Take screenshot filename argument failing when registered to be run on failure:

[ WARN ] Keyword 'Take Screenshot    filename=robotframework-browser-screenshot-{index}' could not be run on failure:
take_screenshot() got multiple values for argument 'filename'

Trace log:

Traceback (most recent call last):
  File "c:\python37\lib\site-packages\Browser\browser.py", line 880, in run_keyword
    raise e
  File "c:\python37\lib\site-packages\Browser\browser.py", line 870, in run_keyword
    return DynamicCore.run_keyword(self, name, args, kwargs)
  File "c:\python37\lib\site-packages\robotlibcore.py", line 94, in run_keyword
    return self.keywords[name](*args, **(kwargs or {}))
  File "c:\python37\lib\site-packages\Browser\keywords\waiter.py", line 93, in wait_for_elements_state
    selector, state, timeout, self.strict_mode
  File "c:\python37\lib\site-packages\Browser\keywords\waiter.py", line 132, in _wait_for_elements_state
    logger.info(response.log)
  File "c:\python37\lib\contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "c:\python37\lib\site-packages\Browser\playwright.py", line 153, in grpc_channel
    raise AssertionError(error.details())

Working fine for positional argument.

To Reproduce Here look at a code snippet:

Take screenshot filename argument failing when registered to be run on failure

[Setup]  New Page  https://www.yahoo.com/
Browser.Register Keyword To Run On Failure  Take Screenshot  filename=robotframework-browser-screenshot-{index}
Click  //button[@name="agree"]
Wait Until Network Is Idle
Wait For Elements State  ddd
[Teardown]  Close Page

Expected behavior Filename argument should be processed correctly and desired filename and path should be set.

Desktop (please complete the following information):

Additional context Please find attached logs

aaltat commented 2 years ago

@allcontributors please add @tomekTieto for bugs.

allcontributors[bot] commented 2 years ago

@aaltat

@tomekTieto already contributed before to bug

aaltat commented 2 years ago

That should work, but looks like it doesn't.

schinckel commented 2 years ago

I'm seeing what I believe is the same error on a Bitbucket Pipelines container.

adrian-evo commented 2 years ago

There seems to be an error in the code snipped above. Adding Browser also in front of Take Screenshot it works, which means in the above code some other Take Screenshot keyword was used:

Browser.Register Keyword To Run On Failure Browser.Take Screenshot filename=

However, I have another problem, not sure if this should be another issue. When using the full path instead of file name, it does not work:

Browser.Register Keyword To Run On Failure Browser.Take Screenshot filename=${OUTPUT DIR}/screenshots/failed/robotframework-browser-screenshot-{index} The output is:

image

Taking a screenshot with the same arguments, normally not on failure, it works.

aaltat commented 11 months ago

This is not fixed, opening

aaltat commented 11 months ago

Fuond the reason, code in https://github.com/MarketSquare/robotframework-browser/blob/main/Browser/browser.py#L909 is too naive and makes wrong assumption. Instead code should look argspec more closely and make better decision about argument types.