robotframework-browser icon indicating copy to clipboard operation
robotframework-browser copied to clipboard

Improve Error message when importing Browser Library, if rfbrowser init was not executed

Open manykarim opened this issue 1 year ago • 3 comments

Describe the bug The error message which is thrown when using

*** Settings ***
Library    Browser

and if a user forgot to install Playwright dependencies via rfbrowser init is not clear-

To Reproduce Steps to reproduce the behavior:

  1. pip install robotframework-browser
  2. Create a new testsuite, e.g. sample.robot
  3. Add a *** Settings *** Section with Library Browser
  4. Check Error message

Expected behavior Error message informs user that rfbrowser init needs to be executed

Error Message:

Import definition contains errors.robotcode.namespace(ImportContainsErrors)
playwright.py(79, 1): Initializing library 'Browser' with no arguments failed: Could not find node dependencies in installation directory `C:\Users\MKASIRIH\AppData\Roaming\Python\Python310\site-packages\Browser\wrapper.` Run `rfbrowser init` to install the dependencies.
Traceback (most recent call last):
File "C:\Users\MKASIRIH\AppData\Roaming\Python\Python310\site-packages\Browser\browser.py", line 739, in __init__
self.playwright = Playwright(
File "C:\Users\MKASIRIH\AppData\Roaming\Python\Python310\site-packages\Browser\playwright.py", line 50, in __init__
self.ensure_node_dependencies()
File "C:\Users\MKASIRIH\AppData\Roaming\Python\Python310\site-packages\Browser\playwright.py", line 79, in ensure_node_dependencies
raise RuntimeError(
RuntimeError: Could not find node dependencies in installation directory `C:\Users\MKASIRIH\AppData\Roaming\Python\Python310\site-packages\Browser\wrapper.` Run `rfbrowser init` to install the dependencies.

manykarim avatar Feb 27 '24 11:02 manykarim

Would you have some longer description what you would like to see in the error message?

aaltat avatar Feb 27 '24 14:02 aaltat

@allcontributors please add @manykarim for bugs

aaltat avatar Mar 01 '24 17:03 aaltat

@aaltat

I've put up a pull request to add @manykarim! :tada:

allcontributors[bot] avatar Mar 01 '24 17:03 allcontributors[bot]

@manykarim

That info was there, but in the end of the line, so users would not see.

Now we anyway do load Playwright only if needed, as a @property, therefore that error comes later. Either if you use JS-Extensions or when you call a keyword.

The error when importing with a jsextension looks like this:

Import definition contains errors.robotcode.namespace(ImportContainsErrors)
playwright.py(85, 1): Initializing library 'Browser' with arguments [ jsextension=/Users/rener/Source/MarketSquare/robotframework-browser/atest/test/05_JS_Tests/funky.js ] failed:
#############################################################
#                                                           #
#  RF-Browser dependencies not found in installation path!  #
#           Run `rfbrowser init` to install.                #
#                                                           #
#############################################################
Installation path: /Users/rener/Source/MarketSquare/robotframework-browser/Browser/wrapper
Traceback (most recent call last):
File "/Users/rener/Source/MarketSquare/robotframework-browser/Browser/browser.py", line 871, in __init__
libraries.append(self._create_lib_component_from_jsextension(js_ext))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/rener/Source/MarketSquare/robotframework-browser/Browser/browser.py", line 968, in _create_lib_component_from_jsextension
response = self.init_js_extension(Path(jsextension))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/rener/Source/MarketSquare/robotframework-browser/Browser/browser.py", line 980, in init_js_extension
with self.playwright.grpc_channel() as stub:
^^^^^^^^^^^^^^^
File "/Users/rener/Source/MarketSquare/robotframework-browser/Browser/browser.py", line 914, in playwright
self._playwright = Playwright(
^^^^^^^^^^^
File "/Users/rener/Source/MarketSquare/robotframework-browser/Browser/playwright.py", line 53, in __init__
self.ensure_node_dependencies()
File "/Users/rener/Source/MarketSquare/robotframework-browser/Browser/playwright.py", line 85, in ensure_node_dependencies
raise RuntimeError(
RuntimeError:
#############################################################
#                                                           #
#  RF-Browser dependencies not found in installation path!  #
#           Run `rfbrowser init` to install.                #
#                                                           #
#############################################################
Installation path: /Users/rener/Source/MarketSquare/robotframework-browser/Browser/wrapper

I think this is now much more obvious. We can not skip the stacktrace, because that is printed by robot framework, but with keyword errors the actual information is less "poluted"

image

Snooz82 avatar Oct 07 '24 15:10 Snooz82