Improve Error message when importing Browser Library, if rfbrowser init was not executed
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:
- pip install robotframework-browser
- Create a new testsuite, e.g. sample.robot
- Add a
*** Settings ***Section withLibrary Browser - 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.
Would you have some longer description what you would like to see in the error message?
@allcontributors please add @manykarim for bugs
@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"