Configuration of VSCode (launch.json)

We try to migrate from RED to Visual Studio Code. It seems it’s not simply done be installing the plugin (GitHub - d-biehl/robotcode: RobotFramework support for Visual Studio Code). Afterwards we need to configure the launch.json file. Because we never worked with VSCode, we haven’t a clue how to do this. Searching for any hints we didn’t find useful informations. Where can we download this file or where do we find hints what to do in concern of the plugin? Or maybe somebody can post the file content here? Or maybe we did miss a certain step during installation? Btw, we had to install all plugins offline because of security restrictions.
Thx, Rainer

Hello Rainer,

normally you don’t need a launch.json. Depending on what settings you need, look settings for the extension in VSCode (Menu File/Preferences/Settings), then select Workspace and on the left side you see the extensions, search for “Robot Code”. Every setting that starts with “Robot:” are settings that corresponds to the “robot” command line parameters. Here you have to set the right things.
If your settings are correct, than you can simply run/debug your tests directly from the green arrow before a test in the editor or from the test explorer view.
Right click on the green arrow, gives you a menu where you can select “Debug” instead of “Run”.

Daniel

Thanks for your quick response. It’s strange, if I setup it on my private machine (Linux/Online), it works as you described, even without changing any setting. If I do the same on the company machine (Windows/Offline), I don’t have green arrows, I don’t have the Test icon on the left side, …
I compared the Robot settings from both machines, seems identical. The only difference: VSC on the company machine has german GUI settings, my machine has English. Both by default because of the OS settings. Do you have any idea?

Can you compare the VSCode versions?

And the other thing, did you install the python extension, and maybe the pylance extension?

Windows has VSC 1.67.1, Linux has 1.67.2. Both have Plugins Python, Pylance and Jupyter.

The VSCode versions are fine.

Did you select the correct python interpreter?

In the “Output View” there are at least 2 entries for RobotCode, one for the extension and another one for the language server. Are there any errors displayed there?

thanks Daniel.

unfortunatly with the windows machine I cannot run any test (thus no output view). I get the message “zum Anpassen von Ausführen und Debuggen erstellen Sie eine launch.json-Datei”.

Regardless this I checked the installed Python: it’s 3.8.10 on my private Linux machine and 3.8.8 on the Windows machine.

On both machines this Python installations are referencend within the VSC settings.json.

Then something with the installation of RobotCode is wrong. Is it shown in the “extensions” tab?

Normally, if RobotCode extension is installed and finds any .robot/.resource files in the workspace, it tries to enable itself and check if we can start a language server, if there is no python interpreter selected, then it ask to select one. Then it checks if a supported version of robotframework is installed, if not it ask you to install one. Does any of this happens at opening the project?

If everything is installed correctly, you can load your project, press F1 and type “Python Select interpreter” to select the correct python interpreter with robotframework installed.

Which version of RobotCode do you use? And wich Robot Framework version?

Thanks, we were interrupted by another task, I come back on Monday probably.

Hi Rainer,

You may have checked this already, I had issues with the language server, because of the requirement for Selenium 4.4+.

Re the green arrows for running the tests, these can be set to not be shown (I turned them off as I would click them by accident…) But I can’t remember where the specific setting for that resides.

Thanks Alan, but we don’t use Selenium. Just API tests so far. In the meantime we uninstalled the extensions and re-installed on command line, at least we have the green arrows now. We go on next days.

Late to the game here, but I found I needed a launch.json for my work projects. To clarify, this file belongs in the .vscode directory:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "robotframework-lsp",
      "name": "Robot Framework: Launch Template",
      "request": "launch",
      "terminal": "integrated",
      "args": ["-V", "${workspaceFolder}/[my_arg_file]"],
      "console": "internalConsole"
    }
  ]
}

In my case, the [my_arg_file] is a YAML file (supports Python primitives), so you’ll need to install YAML. So, in my case, the file would be something like: envArgs.yml

Hope this helps!

Oh, and I should have added the above assumes you’ve installed the RoboCorp Robot Framework extension.

Thanks for all the help here! In the meantime we got it on one machine. But on a second machine with same installations (vsc version, ext versions, …) we still have an error.

After starting a test we have the notification “Running tests …” which never disappears until closing VSC. Also we don’t see any output. We already compared all settings (as we know so far) and also unistalled/installed all extensions twice.
On both machines we have Python+Pylance+Jupyter+JupyterKeymap+JupyterNotebookRenderers+RobotCode

Somebody has a hint what we can check additionally?

Ok, we got it. In case somebody has problems with offline use of VSCode too here some hints:

  • Use the command line to install all extensions (code --install-extension <ext-file-name>)
  • The only setting to set is the path-to-python.exe within the Python-Extension-Settings. RobotCode uses this setting, no need to change other settings.
  • In case of problems uninstall VSCode and delete both (!) % USERPROFILE%.vscode and %APPDATA%\Code before re-installing VSCode (detailed explanation here)

We had a some problems probably because we tried the offline extension installation from within VSCode first, after cleaning and re-installing it was fine.

1 Like

Hi, I think I’m having the same issue. I cannot get the auto-completion for keywords/libraries and etc. I have installed the robot code with python as well as the robotframework too. Any idea how can I enable the features?

Hi Lee, I’m sorry, I transfered this topic to a colleague. What I know is, he installed/reinstalled with different versions … and some day it worked. Not sure, if a wrong version was the reason or any other point.

Hi Daniel, I came across this thread after using your extension.

I currently have my launcher.json file configured like so:

“version”: “0.2.0”,
“configurations”: [
{
“name”: “Python: Remote Attach”,
“type”: “python”,
“request”: “attach”,
“host”: “127.0.0.1”,
“port”: 5678,
}
]

I have a module called run_tests.py that I execute from CLI that interfaces with a device. In this run_tests.py, it will configure the robot environment and launch robot. I can currently debug the python backend with the above launcher.json settings and this added in my main file. At this point, VS code breakpoints will work from the GUI from all of my sub Libraries that are utilized by my test suites.

#5678 is the default attach port in the VS Code debug configurations. Unless a host and port are specified, host defaults to 127.0.0.1
debugpy.listen(5678)
print(“Waiting for debugger attach”)
debugpy.wait_for_client()

Do you know how I could configure your extension for this scenario like I am for python backend to debug my robot cases/custom keywords?

He Jim,

What exactly do you want to do?

Debug RobotFramework test cases “remotely”? Unfortunately this is not possible at the moment.

But if you want to debug only the keywords written in Python, then there are 2 possibilities.

  • there is a setting “robotcode.debug.attachPython”, set it to true and you can also debug the python code.
  • create a robotcode launch config like this:
{
            "name": "RobotCode: Run Current",
            "type": "robotcode",
            "request": "launch",
            "cwd": "${workspaceFolder}",
            "target": "${file}",
            "attachPython": true
},