I'm looking for testing
This chapter will help you to get started with Robot Framework.
Install Python
- Windows
- Linux
- MacOs
Download and run the Python installer
- Select option
Add Python 3.X to PATH
- (optional) install to a sub-folder on root of your drive (e.g. C:\Python3.X)
- Open a command line by
- pressing
Windows key + R
- typing
cmd
and pressingEnter
- pressing
python -V
Open a terminal by either
- pressing
Ctrl
+Alt
+T
- pressing the
Windows key
and typingterminal
- right-clicking in your file explorer and selecting
Open in Terminal
sudo apt update
sudo apt install python3 python3-pip
python3 -V
We will use Homebrew and pyenv to install Python.
Install homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Follow instructions to add brew to path (Those are shown after homebrew installation)
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> $HOME/.profile
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
Install pyenv
brew install pyenv
Add pyenv to Path
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
eval "$(pyenv init -)"
Add Python Build Dependencies
xcode-select --install
brew install openssl readline sqlite3 xz zlib tcl-tk
Install a Python 3.10.6
pyenv install 3.10.6
Tell pyenv to use Python 3.10.6 globally
pyenv global 3.10.6
python --version
You should see something like this:
Python 3.10.6
Check out the official Python Downloads page or the Python Beginner's Guide for more information
Install Robot Framework
Assumptions and other notes
We assume that Python3 and pip are installed.
We use the commands pip
and python
to install packages or run Python scripts.
Depending on your setup, those commands may be pip3
and python3
or pip
and python
.
When we mention the word terminal
, we mean both - a linux terminal (e.g. bash
) or a windows command line (cmd
).
Python allows you to install modules via pip
.
By default, those modules are installed in the global Python environment.
But especially when working on multiple projects, it is more convenient to have a separate Python environment for each project with all the required packages installed (like robotframework
or additional libraries like robotframework-seleniumlibrary
).
To separate the global Python environment from the project environment, you can use a virtual environment
.
We will cover both approaches in the following chapters.
You can type pip show robotframework
to get more information about the installed version of Robot Framework and the install location.
Install Robot Framework globally
- Global
Open your terminal
pip install robotframework
robot --version
You should see something like
Robot Framework 5.x.y (Python 3.x.y)
Install Robot Framework in a Virtual Environment
- Windows
- Linux
- MacOS
We recommend to have a folder on your drive to store your projects, e.g. C:\projects
.
Open your terminal
cd C:\projects
mkdir MyProject
cd MyProject
python -m venv .venv
.venv\Scripts\activate.bat
pip install robotframework
robot --version
You should see something like
Robot Framework 5.x.y (Python 3.x.y)
You can type pip show robotframework
to get more information about the installed version of Robot Framework and the install location.
The virtual environment can be deactivated by typing venv\Scripts\deactivate.bat
.
If you prefer to use PowerShell
instead of cmd
, you can use the following commands for activating and deactivating the virtual environment:
- Activate:
venv\Scripts\activate.ps1
- Deactivate:
venv\Scripts\deactivate.ps1
We recommend to have a folder on your drive to store your projects, e.g. ~/projects
.
Open your terminal
cd ~/projects
mkdir MyProject
cd MyProject
python -m venv .venv
source .venv/bin/activate
pip install robotframework
robot --version
You should see something like
Robot Framework 5.x.y (Python 3.x.y)
The virtual environment can be deactivated by typing source .venv/bin/deactivate
.
We recommend to have a folder on your drive to store your projects, e.g. ~/projects
.
Open your terminal
cd ~/projects
mkdir MyProject
cd MyProject
Tell pyenv to use Python 3.10.6 (if you haven't done so already).
Either globally
pyenv global 3.10.6
Or locally (for the current folder only)
pyenv local 3.10.6
Create and activate a new Virtual Environment and install robotframework
python -m venv .venv
source .venv/bin/activate
pip install robotframework
robot --version
You should see something like
Robot Framework 5.x.y (Python 3.x.y)
The virtual environment can be deactivated by typing source .venv/bin/deactivate
.
Other Recommendations
Managing Dependencies with poetry
Poetry is a tool for dependency management and packaging in Python.
It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.
You can use it when you start any new project python or robotframework project.
Install poetry by following the official instructions.
- Windows
- Linux
- MacOS
Open PowerShell and run the following command:
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -
💡If you have installed Python through the Microsoft Store, replace py
with python
in the command above.
Open your terminal and run the following command:
curl -sSL https://install.python-poetry.org | python3 -
💡On some systems, python
may still refer to Python 2 instead of Python 3. So we used python3
in the command above.
Open your terminal and run the following command:
curl -sSL https://install.python-poetry.org | python3 -
💡On some systems, python
may still refer to Python 2 instead of Python 3. So we used python3
in the command above.
Run poetry once to check if it's installed.
poetry --version
Virtual Environments folder
Poetry will save the virtual enviromentson in the .poetry/envs
folder. You can change that setting and store your virtual environment in the project folder by running
poetry config virtualenvs.in-project true
Initialize a new project
To initialize a new project, run the following command in your terminal:
poetry init
Poetry will ask you some questions about your project. You can leave the default values by pressing Enter
or enter your own values.
Example:
This command will guide you through creating your pyproject.toml config.
Package name [your-project-name]:
Version [0.1.0]:
Description []:
Author [Your Name <your.email@example.com>, n to skip]:
License []:
Compatible Python versions [^3.10]:
Would you like to define your main dependencies interactively? (yes/no) [yes] no
Would you like to define your development dependencies interactively? (yes/no) [yes] no
After the initialization, you will see a new file called pyproject.toml
in your project folder. This file contains all the information about your project and the dependencies.
Add dependencies
To add a dependency, run the following command in your terminal:
poetry add robotframework
You can also add multiple dependencies at once:
poetry add robotframework robotframework-browser robotframework-requests
On the first run, poetry will create a virtual environment for your project and install the dependencies.
Run Commands in the Virtual Environment
To run commands in the virtual environment, you can use the poetry run
command.
poetry run robot --version
To e.g. install the playwright dependencies for robotframework-browser, you can run the following command:
poetry run rfbrowser init
You can also use the poetry shell
command to open a shell in the virtual environment.
All commands you run in this shell will be executed in the virtual environment.
poetry shell
(.venv) robot --version
Check out the official documentation for more information.
There is also a great Lightning Talk Project and package management: Poetry for robots from RoboCon 2022