We will use the mkvirtualenv command to create a virtual Python environment named ‘robotframework’.
If, by any chance, you have multiple Python versions installed on your system, you will need to use the -p switch to specify the Python version that you’d like the virtual environment to be based on:
mkvirtualenv -p 3.10 robotframework
If you have multiple Python versions, but omit the -p switch, then virtualenv will use the Python version that is the first (going top down) on your PATH (see above).
As mentioned, ‘robotframework’ will be the name of our virtual environment. Naturally, in a real-life context (especially when multiple virtual environments are in use) you’d probably use a more descriptive, meaningful name.
Running the appropriate mkvirtualenv command will create a virtual environment in our WORK_HOME target folder:
The prefix (robotframework) on the command line indicates that the environment has not only been created, but has also been activated as well. If you want to know more about this (or about the mkvirtualenv command in particular), please see the first two sections of this earlier post.
The mkvirtualenv command will create a folder structure in our WORKKON_HOME folder.
The root folder of this structure is named ‘robotframework’, since that is the name that we gave to our virtual env.
If you want to learn more about this folder structure, please read the relevant section of this article.
For now, we can exit the command line and move on to the next step.
We are now ready for the installation of Robot Framework and required test libraries.
Let’s start with the former.
First we need to activate the virtual environment that we want to use in our future RF projects (and that we will therefore have to bind to the RF VSC extension later on). By activating that environment on the command line, our stack will not be installed globally, but only for (i.e. within) the relevant virtual environment.
Therefore we will use the virtualenvwrapper-win workon command to activate the environment and subsequently use the pip install command to install RF into the activated env.
To install test libraries, such as the BrowserLibrary or SoapLibrary, you can also use pip install. Here we will do so, but in combination with using a requirements file (click the image to download it):
This is an example file. Please make sure to delete all lines that install packages that you are not interested in (and/or add lines for other packages).
On the command line, make sure that our environment is activated and issue the command:
pip install -r requirements.txt
Of course, you may have to specify the path to the file, e.g.:
pip install -r C:\Tmp\requirements.txt
This will install all packages that are specified in the requirements file.
If you want more details, please see this section on the -r switch.
Let’s do a quick check to see whether the installed development stack functions properly. As follows (click an image to enlarge):
With that behind us, let’s try some simple Robot Framework development to complete our little test! To that purpose, let’s first save our file (using [Ctrl + s]) and then write and run a very simple demo test case.
Even in this simple demo case we can see several RF-LS services in action, such as syntax highlighting/coloring, syntax analysis & validation and code completion.
Also note that upon saving the file, it’s extension had been correctly (and ‘automagically’) set to .robot. Similarly, where we to open a .robot (or .resource) file in the File Explorer, the RF-LS extension would also be activated for the code in that file.
However, there are a lot of very interesting configuration options that may boost our productivity.
These options pertain to the Robot Framework Language Server extension as well as to Visual Studio Code itself.
In the next couple of posts we will therefore take a look at some of these options, so as to understand their purpose, their inner working and how to optimize our development environment (and productivity) through them.
So please stay tuned for the next part!
Please join the discussion: place a comment on this page.
The comment will be immediately visible in this comment section.
Please note a Github account is required to comment.