robotcodedev / robotcode

RobotFramework support for Visual Studio Code
https://robotcode.io
Apache License 2.0
177 stars 14 forks source link

[QUESTION] Can not resolve "Browser" (Playwright) Library, Initializing library 'Browser' with no arguments failed #198

Closed danielHalan closed 8 months ago

danielHalan commented 8 months ago

Please describe.

On one of the installations with VS Code + Robot Code (same version as other workstations working), there is an error that it can not resolve the "Browser" Library.

The error says it needs to be initialized (rfbrowser init), which I have done multiple times, with same result. Could not find node dependencies in installation directory "C:\Python\Lib\site-packages\Browser\wrapper" Run "rfbrowser init" to install the dependencies.

Have also confirmed that there are only one Python path in %PATH% and it is correct, and same as in the error message.

image

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

Does anyone recognize the issue?

Desktop (please complete the following information): VS Code Version 1.85.1 RobotCode Version v0.68.3 OS: Windows Python Version 3.12.1 RobotFramework Version 7.0 Additional tools robocop

danielHalan commented 8 months ago

Got it working by, a complete uninstall of Node, Python & VS Code, including Deleting the folders after uninstall and re-installed all applications. and Robot Framework & Browser.

Must have been an old file disturbing the initialization.

bennesp commented 8 months ago

I have this error every month or so, do you have any suggestion on how to workaround this issue? I can't think of reinstalling the entire stack every time every month or so

bennesp commented 8 months ago

It seems that editing file .venv/lib/python3.11/site-packages/Browser/playwright.py and saving fixes the error.

So every time I:

and everything works

This is still very awkward, it seems like a cache not invalidated. At least I found a workaround, documented here for future references

d-biehl commented 8 months ago

Begin by (re)initializing the browser library with rfbrowser init (consider using rfbrowser clean-node before if needed). Afterward, execute the command RobotCode: Clear Cache and Restart Language Server by pressing F1. This action will reset the library cache, and the Browser library should function properly again.

bennesp commented 8 months ago

I will give it a try for sure next time, thank you very much for the precious suggestions!