Problem with robot framework and browser library

Greetings to all,

I’m facing problem that browser library isn’t seen in ide/ Pycharm.
I’ve created clean install of an Pycharm, installed robot framework and browser library.
Test can be ran via terminal with ‘robot example.robot’.

But ide doesn’t recognize browser library nor any of the keywords of the browser library.

I’m using macOs, 14.2.1 (23C71),
intel processor 2,6 GHz 6-Core Intel Core i7.

node -v
v18.13.0
npm -v
9.6.6
Python version is 3.12.1.
pip list is returning the following
Package Version


attrs 23.2.0
certifi 2024.2.2
click 8.1.7
grpcio 1.59.3
grpcio-tools 1.59.3
h11 0.14.0
idna 3.6
outcome 1.3.0.post0
overrides 7.7.0
pip 23.3.2
protobuf 4.25.1
PySocks 1.7.1
robotframework 7.0
robotframework-assertion-engine 3.0.3
robotframework-browser 18.0.0
robotframework-pythonlibcore 4.3.0
robotframework-seleniumlibrary 6.2.0
selenium 4.17.2
setuptools 69.0.3
sniffio 1.3.0
sortedcontainers 2.4.0
trio 0.24.0
trio-websocket 0.11.1
typing_extensions 4.9.0
urllib3 2.2.0
wrapt 1.16.0
wsproto 1.2.0

Nodejs is installed, in terminal both npm and node are found. Also both are set in path
Ide is returning the following error.

Unresolved library: Browser.
Error generating libspec:
Initializing library 'Browser' with no arguments failed: Couldn't execute node. Please ensure you have node.js installed and in PATH. See https://nodejs.org/ for instructions. Original error is [Errno 2] No such file or directory: 'node'

Yesterday I’ve also installed the xcode and installed robot framework in /Applications/Xcode.app/Contents/Developer/usr/bin

Any help appreciated.

I’ve created new virtual env, with python 3.12 and installed everything on new.
Browser library isn’t found.

I had a similar behaviour last week in VSCode with RobotCode on Windows. Execution of tests worked, but RobotCode Plugin somehow could not load Browser library for keyword-auto-complete, because the exact same error you mentioned.

In VSCode, I could see the actualy stacktrace where that message is thrown. It is a sanity check in Browser library checking if node is installed. For some reason, it does not find node (it does not make sense, because obviously it is installed and is working…). You can click on the error message in the stacktrace and probably end up in playwright.py of Browser library with these lines:

    def ensure_node_dependencies(self):
        # Checks if node is in PATH, errors if it isn't
        try:
            run(["node", "-v"], stdout=DEVNULL, check=True)
        except (CalledProcessError, FileNotFoundError, PermissionError) as err:
            raise RuntimeError(
                "Couldn't execute node. Please ensure you have node.js installed and in PATH. "
                "See https://nodejs.org/ for instructions. "
                f"Original error is {err}"
            )

What fixed it for me was commenting out the run statement:

    def ensure_node_dependencies(self):
        # Checks if node is in PATH, errors if it isn't
        try:
            # run(["node", "-v"], stdout=DEVNULL, check=True)
           pass
        except (CalledProcessError, FileNotFoundError, PermissionError) as err:
            raise RuntimeError(
                "Couldn't execute node. Please ensure you have node.js installed and in PATH. "
                "See https://nodejs.org/ for instructions. "
                f"Original error is {err}"
            )

You probably get a warning that these hack is not persistent as any update on Browser will overwrite it. But that fixed the issue for me. After that, RobotCode would could load the keywords correctly.

This obviously is not a good solution, but hopefully it works until a proper answer is found :slight_smile:

Regards,
Markus

FileNotFound when trying to just run node -v sounds like the issue is with PATH environment. Since its the LSP that run’s this code to get the information about what keywords the library exposes (for auto-complete) - env has to be set before that process is spawned and in place where it gets automatially added.

For example; installing node or libraries after VSCode has been started (and still running) – this is what happens. Restarting the whole machine (because, windows) should help.

Same thing with the lsp – if for some reason that process has been running before node was installed - same thing happens. Adding to the PATH is not automatically appended for each running process…

Using stuff like NVM or similar on windows could also be culprint …

As “hack”, one could make something add a wrapper script to a known location that is always in the path that will just delegate command line arguments to actual node binary and that would help so that you dont need to modify the playwright.py.