Skip to content

Get Started with VS Code

Let's explore how you can enhance your development experience with the RobotCode - Robot Framework Support extension for Visual Studio Code. We'll walk you through the steps of installing the RobotCode extension, configuring your environment, and ensuring smooth functionality. Get ready to unleash the power of RobotCode and Robot Framework in no time!

If you prefer to watch a video tutorial, check out the tutorial I gave at RoboCon 2024, which covers installing, setting up and using RobotCode in Visual Studio Code:

To install RobotCode and set up your Robot Framework project in Visual Studio Code, follow these steps:

  1. Open Visual Studio Code.
  2. Go to the Extensions tab by pressing CONTROL+SHIFT+X or COMMAND+SHIFT+X on Mac.
  3. Search for RobotCode and install the RobotCode - Robot Framework Support extension. This will also install the Python and Python Debugger extensions.
  4. (Recommended) Install the Even Better TOML extension for better handling of .toml files, which will be useful when configuring your project settings in Configure Your Project.
Tip: Add to Workspace Recommendations (Optional)

To ensure a consistent development environment for everyone working on this project, follow these steps:

  1. Right-click on the RobotCode extension in the Extensions tab.
  2. Click on Add to Workspace Recommendations. This will prompt all team members to install the RobotCode extension, creating a unified development environment.

See also the VS Code documentation on how to work with extensions.

First you need to open your project folder in Visual Studio Code. You can do this by selecting File > Open Folder menu and navigating to the root folder of your project. If you don't have a project folder yet, you can also create a new folder in the "Open Folder" dialog.

It is a good style to manage your project dependencies in a requirements.txt file. This file lists all the Python packages required for your project, including Robot Framework and any other dependencies you may need. This file can be used to install all the dependencies at once, ensuring that your project runs consistently across different environments.

Create a requirements.txt file in the root folder of your project and add the following content:

requirements.txt
robotframework

If you require additional dependencies, you can include them in the requirements.txt file. For instance, if you wish to utilize robotframework-robocop for formatting and linting your robot files and the Browser library for website testing, you can add the following line to the requirements.txt file:

requirements.txt
robotframework
robotframework-robocop
robotframework-browser

To install the dependencies listed in the requirements.txt file, open the terminal in Visual Studio Code and run the following command:

Terminal window
pip install -r requirements.txt

This command will install the Robot Framework and any other dependencies listed in the requirements.txt file. Make sure to run this command in the root folder of your project.

It is recommended to use a virtual python environment for your project to manage dependencies and ensure consistency across different environments. A virtual environment allows you to isolate your project's dependencies from the system-wide Python installation, ensuring that your project runs consistently across different environments.

What is a Virtual Python Environment?

A virtual environment is a self-contained directory that contains a Python installation along with all the necessary packages and dependencies for a specific project.

Using a virtual environment is beneficial for several reasons:

  • Dependency management: By creating a virtual environment, you can easily manage and install project-specific dependencies without affecting other Python projects or the system-wide Python installation.
  • Reproducibility: With a virtual environment, you can recreate the exact environment in which your project was developed, making it easier to reproduce and debug issues.

More information about virtual environments can be found in the Python documentation.

There are several ways to create a virtual Python environment and manage your project and its dependencies, depending on your preference and workflow. Below, we use the standard built-in Python methods and describe two ways for creating a virtual environment: the "VSCode way" and the "Python way". Some other good options to manage your Robot Framework/Python environment are hatch, poetry or pipenv

VSCode provides a built-in feature to create a virtual environment for your Robot Framework/ Python project. This feature allows you to create a virtual environment and install dependencies directly from the editor. You can also specify the Python version and include one or more requirements.txt files for managing project dependencies.

You can refer to the Python environments in VSCode Documentation for more information.

The short version of the steps are:

  1. Open the Command Palette by pressing CONTROL+SHIFT+P or COMMAND+SHIFT+P on Mac, then search for Python: Create Environment, and select it.
  2. Choose Venv, this will create a virtual environment in the .venv folder in your project.
  3. Select your preferred Python version.
  4. Check the box for requirements.txt and click OK.

RobotCode uses the Python environment that the Python extension selects for the workspace folder. If you want to switch to a different Python interpreter with Robot Framework installed for your project, you can select the Python interpreter in Visual Studio Code. This ensures that the correct Python environment is used for running your Robot Framework tests.

To select the Python interpreter, follow these steps:

  1. Open the Command Palette by pressing CONTROL+SHIFT+P or COMMAND+SHIFT+P on Mac.
  2. Search for RobotCode: Select Python Environment and select it. It opens the environment picker of the Python extension for the workspace folder.
  3. Choose the Python interpreter associated with your virtual environment or the Python interpreter with Robot Framework installed.

As long as the selected environment has no Robot Framework, RobotCode shows a message that says so. You don't need to restart anything: when you install Robot Framework into the environment, RobotCode notices it within a few seconds and starts, and it also notices a virtual environment that you create in the folder; see The Python environment.

  1. Open the terminal in Visual Studio Code. You can do this by pressing CONTROL+` or selecting Terminal > New Terminal from the menu. If there is an existing terminal, you can close it and open a new one to ensure that the virtual environment is activated.
  2. Run the command robot --version to check if Robot Framework is installed correctly.

If the command returns the Robot Framework version number, your installation is successful! With a .robot file open, the language status shows the Robot Framework version that RobotCode uses. If you encounter any errors, ensure that your virtual environment is activated and that all dependencies in requirements.txt have been installed.

Create a first.robot file in your project with the following code to demonstrate a basic example of logging a string message to the debug console:

first.robot
*** Test Cases ***
First Test Case
Log Hello world

To run this test file, press the green play button next to the First Test Case test case in the code. You should see the Hello world output displayed in the Debug Console of Visual Studio Code.

And that's it! To learn how to write, navigate, run and debug your tests with RobotCode in VS Code, continue with Working in VS Code. If you have any questions or run into issues, check out the guides or join our community on Slack #robotcode for support. Happy coding!

Released under the Apache-2.0. Copyright © 2022-present Daniel Biehl