|
1 |
| -# Get Started |
| 1 | +# Let's get started!!! |
| 2 | + |
| 3 | +Let's explore how you can enhance your development experience with RobotCode - Robot Framework 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! |
2 | 4 |
|
3 |
| -Welcome to RobotCode! In this section, we will get your Visual Studio Code set up and go through the basics: installing the extension, setting up your environment, and verifying everything is working smoothly. |
4 | 5 |
|
5 | 6 | ## Requirements
|
| 7 | + |
6 | 8 | - Python 3.8 or above
|
7 | 9 | - Robotframework version 4.1 and above
|
8 | 10 | - VSCode version 1.86 and above
|
9 | 11 |
|
10 | 12 | ## Installing RobotCode
|
11 | 13 |
|
| 14 | +To install RobotCode and set up your Robot Framework project in Visual Studio Code, follow these steps: |
| 15 | + |
12 | 16 | 1. Open Visual Studio Code.
|
13 |
| -2. Inside Visual Studio Code, create a new project folder or open an existing one where you want to set up your Robot Framework project. |
14 |
| -3. Go to the **Extensions** tab (Shortcut key <kbd>CONTROL</kbd>+<kbd>SHIFT</kbd>+<kbd>X</kbd>). |
15 |
| -4. Search for **RobotCode** and install the extension {.inline-icon} [RobotCode - Robot Framework Support](https://marketplace.visualstudio.com/items?itemName=d-biehl.robotcode "RobotCode Extension"). This will also install the **Python** and **Python Debugger** extensions. |
16 |
| -5. **(Recommended)** Install the **Even Better TOML** extension for handling `.toml` files more effectively. This will be helpful when setting up your project settings in the [Configuration](./configuration) section. |
| 17 | +2. Go to the **Extensions** tab by pressing [[CONTROL+SHIFT+X]] or [[COMMAND+SHIFT+X]] on Mac |
| 18 | +3. Search for **RobotCode** and install the [RobotCode - Robot Framework Support](https://marketplace.visualstudio.com/items?itemName=d-biehl.robotcode) extension. This will also install the **Python** and **Python Debugger** extensions. |
| 19 | +4. *(Recommended)* Install the **Even Better TOML** extension for better handling of `.toml` files, which will be useful when configuring your project settings in the [Configuration](./configuration) section. |
| 20 | + |
| 21 | + |
| 22 | +::: details Tip: Add to Workspace Recommendations (Optional) |
| 23 | + |
| 24 | +To ensure a consistent development environment for everyone working on this project, follow these steps: |
| 25 | + |
| 26 | +1. Right-click on the RobotCode extension in the Extensions tab. |
| 27 | +2. Click on **Add to Workspace Recommendations**. This will prompt all team members to install the RobotCode extension, creating a unified development environment. |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +::: |
| 32 | + |
| 33 | +See also the VSCode Documention on how to work with extensions [here](https://code.visualstudio.com/docs/editor/extension-marketplace). |
| 34 | + |
| 35 | + |
| 36 | +## Setup a Robot Framework Project |
| 37 | + |
| 38 | +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. |
| 39 | + |
| 40 | +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. |
17 | 41 |
|
18 |
| -After installation: |
19 |
| - - Right-click on the RobotCode extension in the Extensions tab. |
20 |
| - - Click **Add to Workspace Recommendations** to ensure that all team members working on this project are prompted to install the RobotCode extension, creating a consistent development environment for everyone. |
| 42 | +::: tip Note |
| 43 | +However, it's important to note that there are alternative and better methods for setting up a Robot Framework project. Tools like [Hatch](https://hatch.pypa.io/) or [Poetry](https://python-poetry.org/) offer additional features and flexibility for managing project dependencies and environments. |
| 44 | +::: |
21 | 45 |
|
22 |
| -{style="width: 30%;"} |
| 46 | +Create a `requirements.txt` file in the root folder of your project and add the following content: |
23 | 47 |
|
24 |
| -## Initialize an Empty Project |
| 48 | +```requirements.txt [requirements.txt] |
| 49 | +robotframework |
| 50 | +``` |
25 | 51 |
|
26 |
| -To get started with your Robot Framework project, we'll create a `requirements.txt` file to list all necessary dependencies, and set up a virtual Python environment to ensure these dependencies are installed in an isolated space, avoiding conflicts with other projects. |
| 52 | +If you require additional dependencies, you can include them in the `requirements.txt` file. For instance, if you wish to utilize [robotframework-tidy](https://github.com/MarketSquare/robotframework-tidy) for formatting your robot files and the [Browser library](https://robotframework-browser.org/) for website testing, you can add the following line to the `requirements.txt` file: |
27 | 53 |
|
28 |
| -1. **Create a `requirements.txt` file** in the root folder of your project and add the following dependencies: |
29 |
| -::: code-group |
30 |
| -```txt:line-numbers [requirements.txt] |
| 54 | +```requirements.txt [requirements.txt] |
31 | 55 | robotframework
|
32 | 56 | robotframework-tidy
|
| 57 | +robotframework-browser |
33 | 58 | ```
|
| 59 | + |
| 60 | +### Installing Dependencies |
| 61 | + |
| 62 | +::: warning |
| 63 | +Depending on your requirements and system environment, it is advisable to avoid using the system python interpreter for development. Utilizing the system python interpreter can potentially cause conflicts with other projects or system dependencies. Instead, it is recommended to create a virtual environment for your project. Please refer to the [Creating a Virtual Python Environment](#creating-a-virtual-python-environment) section for detailed instructions. |
| 64 | + |
| 65 | +However, there are scenarios where using the system python interpreter is acceptable, such as when working with a docker container or a CI/CD pipeline. In such cases, you can skip the virtual environment setup and directly install the dependencies to the system python interpreter. |
| 66 | + |
| 67 | +If you want to use a virtual environment, please continue with the [Creating a Virtual Python Environment](#creating-a-virtual-python-environment) section. |
| 68 | +::: |
| 69 | + |
| 70 | +To install the dependencies listed in the `requirements.txt` file, open the terminal in Visual Studio Code and run the following command: |
| 71 | + |
| 72 | +```shell |
| 73 | +pip install -r requirements.txt |
| 74 | +``` |
| 75 | + |
| 76 | +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. |
| 77 | + |
| 78 | + |
| 79 | +#### Creating a Virtual Python Environment |
| 80 | + |
| 81 | +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. |
| 82 | + |
| 83 | +::: details What is a Virtual Python Environment? |
| 84 | + |
| 85 | +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. |
| 86 | + |
| 87 | +Using a virtual environment is beneficial for several reasons: |
| 88 | +- 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. |
| 89 | +- Version control: Including the virtual environment directory in your project's version control system ensures that all developers working on the project have the same environment setup, avoiding compatibility issues. |
| 90 | +- 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. |
| 91 | + |
| 92 | +More informations about virtual environments can be found in the [Python documentation](https://docs.python.org/3/library/venv.html). |
| 93 | + |
34 | 94 | :::
|
35 | 95 |
|
36 |
| -2. **Set up your Python environment:** |
| 96 | +There are several ways to create a virtual Python environment and managing you project and project dependencies, depending on your preference and workflow. Below, we use the standard builtin python methods and describe two ways for creating a virtual environment: the "VSCode way" and the "Python way". |
| 97 | +Some other good options to manage your Robot Framework/Python environment are [hatch](https://hatch.pypa.io/), [poetry](https://python-poetry.org/) or [pipenv](https://pipenv.pypa.io/en/latest/) |
| 98 | + |
| 99 | +:::tabs |
| 100 | +=== The VSCode way |
| 101 | + |
| 102 | +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. |
| 103 | + |
| 104 | +You can refer to the [Python environments in VSCode Documentation](https://code.visualstudio.com/docs/python/environments) for more information. |
37 | 105 |
|
38 |
| -A virtual environment is a self-contained directory that contains a Python installation for a particular version of Python, plus a number of additional packages. This helps keep your project dependencies isolated from other projects. In this step we will let Visual Studio Code create a virtual environment using the selected Python version, install the dependencies listed in requirements.txt, and activate the virtual environment. This ensures that your project has all the necessary packages and an isolated environment for development. |
| 106 | +The short version of the steps are: |
39 | 107 |
|
40 |
| -1. Click on **Create Environment** in Visual Studio Code. If this button isn't visible, |
41 |
| - you can alternatively open the Command Palette by pressing |
42 |
| - <kbd>CONTROL</kbd>+<kbd>SHIFT</kbd>+<kbd>P</kbd>, then search for **Python: Create Environment**, and select it. |
43 |
| -2. Choose **venv**, which stands for Virtual Environment. |
| 108 | +1. Open the Command Palette by pressing |
| 109 | + [[CONTROL+SHIFT+P]] or [[COMMAND+SHIFT+P]] on Mac, then search for `Python: Create Environment`, and select it. |
| 110 | +2. Choose `Venv`, this will create a virtual environment in the `.venv` folder in your project. |
44 | 111 | 3. Select your preferred Python version.
|
45 | 112 | 4. Check the box for requirements.txt and click OK.
|
46 | 113 |
|
47 | 114 | 
|
48 | 115 |
|
| 116 | +=== The Python way |
| 117 | + |
| 118 | +To create a virtual environment in Python, you can use the built-in `venv` module. This module provides a command-line interface as well as a Python API for managing virtual environments. |
| 119 | + |
| 120 | +Open a Terminal in VSCode and ensure you are in the root folder of your project. Then follow these steps: |
| 121 | + |
| 122 | +1. Create a virtual environment: |
| 123 | + ``` |
| 124 | + python -m venv .venv |
| 125 | + ``` |
| 126 | +
|
| 127 | +2. Activate the virtual environment: |
| 128 | + ::: code-group |
| 129 | + ``` shell [Windows PowerShell/pwsh] |
| 130 | + myenv\Scripts\activate.ps1 |
| 131 | + ``` |
| 132 | +
|
| 133 | + ``` shell [Windows CMD] |
| 134 | + myenv\Scripts\activate.cmd |
| 135 | + ``` |
| 136 | +
|
| 137 | + ``` shell [Mac/Linux] |
| 138 | + source myenv/bin/activate |
| 139 | + ``` |
| 140 | + ::: |
| 141 | +
|
| 142 | +3. Install project-specific dependencies: |
| 143 | + ``` |
| 144 | + pip install -r requirements.txt |
| 145 | + ``` |
| 146 | +::: |
| 147 | +
|
| 148 | +
|
| 149 | +::: tip |
| 150 | +Remember to include the virtual environment directory `.venv` in your project's `.gitignore` file to avoid committing unnecessary files to your version control system. |
| 151 | +""" |
| 152 | +::: |
| 153 | +
|
| 154 | +## Selecting the Python Interpreter |
| 155 | +
|
| 156 | +After creating a virtual environment or 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. |
| 157 | +
|
| 158 | +To select the Python interpreter, follow these steps: |
| 159 | +
|
| 160 | +1. Open the Command Palette by pressing [[CONTROL+SHIFT+P]] or [[COMMAND+SHIFT+P]] on Mac. |
| 161 | +2. Search for `Python: Select Interpreter` and select it. |
| 162 | +3. Choose the Python interpreter associated with your virtual environment or the Python interpreter with Robot Framework installed. |
| 163 | +
|
| 164 | +
|
49 | 165 | ## Verifying the Installation
|
50 |
| -1. Open the terminal in Visual Studio Code. Make sure you are in the root folder of your project. |
| 166 | +
|
| 167 | +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. |
51 | 168 | 2. Run the command `robot --version` to check if Robot Framework is installed correctly.
|
52 | 169 |
|
53 |
| -If the command returns the Robot Framework version number, your installation is successful! If you encounter any errors, ensure that your virtual environment is activated and that all dependencies in `requirements.txt` have been installed. |
| 170 | +If the command returns the Robot Framework version number, your installation is successful! |
| 171 | +If you encounter any errors, ensure that your virtual environment is activated and that all dependencies in `requirements.txt` have been installed. |
54 | 172 |
|
55 | 173 | ## Create and Run Your First Suite/Test
|
| 174 | +
|
56 | 175 | 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:
|
57 | 176 |
|
58 |
| -::: code-group |
59 |
| -```robot:line-numbers [first.robot] |
| 177 | +
|
| 178 | +```robot [first.robot] |
60 | 179 | *** Test Cases ***
|
61 | 180 | First Test Case
|
62 | 181 | Log Hello world
|
63 | 182 |
|
64 | 183 | ```
|
65 |
| -::: |
| 184 | + |
66 | 185 |
|
67 | 186 | To run this test file, press the green play button next to the `First Test Case` keyword in the code.
|
68 | 187 | You should see the `Hello world` output displayed in the **Debug Console** of Visual Studio Code.
|
69 | 188 |
|
70 |
| -{style="width: 70%;"} |
| 189 | + |
71 | 190 |
|
72 | 191 | And that's it! If you have any questions or run into issues, check out the RobotCode documentation or join our community in slack for support. Happy coding!
|
0 commit comments