PyCharm's support for Robot Framework

Contents
Introduction
.robot files
Python interpreter
Installing Robot Framework
Running a simple test
Edit Configurations…
Running tests with libraries
Running tests with options
Working directory
Related articles

Introduction

This article will show you how to run tests written in Robot Framework in PyCharm.

First, we will demonstrate the selection of Python interpreter , then editing the configuration

We will also consider support for Robot Framework syntax and imports in PyCharm

Support for .robot files

To highlight the syntax of .robot files and drill deeper into the code, simply install the Intellibot or Intellibot patched for Selenium plugin. In order to highlight the syntax of .robot files and be able to fall down deeper into the code, you previously had to install the Intellibot or Intellibot patched for Selenium plugin

They did good syntax highlighting, but did not allow you to fall down into keyword sources or Python libraries.

A modern solution to these problems is the Hyper RobotFramework Support plugin

Robot Framework Support in PyCharm image from website www.aredel.com
Hyper RobotFramework Support
Плагин

Support for .resource files

If you need support for .resource files, PyCharm offered to install Robot Framework Language Server.

But with the advent of Hyper, this need disappeared.

Language Server had to be configured immediately after installation

Robot Framework Support in PyCharm image from website www.aredel.com

Robot Framework Support in PyCharm image from website www.aredel.com

Banner Image

Python interpreter

If you use the environment that is automatically created by PyCharm - continue working with it.

If you prefer to create your own virtual environment for Python - do it the way you are used to.

In this example, the environment was created using venv

python -m venv venv

If the interpreter is not selected yet:

In the lower right corner of the window PyCharm click

Add New Interpreter Add Local Interpreter…

Select Existing in the Environment field and specify the path to the newly created virtual environment

C:\Users\Andrei\robot\venv\Scripts\python.exe

If the interpreter is not selected yet:

Click on the lower right corner of the window PyCharm

Configuring Python Interpreter for Robot Framework Robot Framework Support in PyCharm image from website www.aredel.com image from www.aredel.com website
Configuring Python Interpreter in PyCharm
https://aredel.com

Click Add New Interpreter

Configuring Python Interpreter for Robot Framework Robot Framework Support in PyCharm image from website www.aredel.com image from www.aredel.com website
Configuring Python Interpreter in PyCharm
https://aredel.com

Click Add Local Interpreter…

Configuring Python Interpreter for Robot Framework Robot Framework Support in PyCharm image from website www.aredel.com image from www.aredel.com website
Configuring Python Interpreter in PyCharm
https://aredel.com

Select the interpreter from the drop-down list, or click

Configuring Python Interpreter for Robot Framework Robot Framework Support in PyCharm image from website www.aredel.com image from www.aredel.com website
Configuring Python Interpreter in PyCharm
https://aredel.com

Specify the path to python.exe from your virtual environment

Configuring Python Interpreter for Robot Framework Robot Framework Support in PyCharm image from website www.aredel.com image from www.aredel.com website
Configuring Python Interpreter in PyCharm
https://aredel.com

The name of the interpreter should appear in the lower right corner

Configuring Python Interpreter for Robot Framework Robot Framework Support in PyCharm image from website www.aredel.com image from www.aredel.com website
Configuring Python Interpreter in PyCharm
https://aredel.com

Installing Robot Framework

After the interpreter is selected , make sure that the Robot Framework itself is installed in it.

If the robot is not installed, install it either with the command

python -m pip install robotframework

Or through the interpreter settings:

Go to the interpreter settings either through the lower right corner or through

Settings Project Python Interpreter

Click +

Installing Robot Robot Framework Support in PyCharm image from website www.aredel.com image from www.aredel.com website
Installing Robot Framework in PyCharm
https://aredel.com

In the search box, type robotframework

Click Install Package

Installing Robot Robot Framework Support in PyCharm image from website www.aredel.com image from www.aredel.com website
Installing Robot Framework in PyCharm
https://aredel.com

Click Close

Installing Robot Robot Framework Support in PyCharm image from website www.aredel.com image from www.aredel.com website
Installing Robot Framework in PyCharm
https://aredel.com

robotframework should appear in the list of installed packages

Installing Robot Robot Framework Support in PyCharm image from website www.aredel.com image from www.aredel.com website
Installing Robot Framework in PyCharm
https://aredel.com

Running a simple test

Tests can be run in the PyCharm terminal by running the command

python -m robot my_test.robot

By a simple test we mean a test that does not import external resources and libraries. That is, it does not require manipulations with the system path .

To run tests using SHIFT + F10 or the button - you need to edit the file launch configuration

Edit Configurations…

If the configuration has not been set up it will be displayed as Current File

Click on the configuration name, for example, Current File

Setting up PyCharm's launch configuration for Robot Robot Framework Support in PyCharm image from website www.aredel.com image from www.aredel.com website
Setting up the launch configuration
https://aredel.com

Select Edit Configurations…

Setting up PyCharm's launch configuration for Robot Robot Framework Support in PyCharm image from website www.aredel.com image from www.aredel.com website
Setting up the launch configuration
https://aredel.com

Click +

Setting up PyCharm's launch configuration for Robot Robot Framework Support in PyCharm image from website www.aredel.com image from www.aredel.com website
Setting up the launch configuration
https://aredel.com

Select Robot from the list

Setting up PyCharm's launch configuration for Robot Robot Framework Support in PyCharm image from website www.aredel.com image from www.aredel.com website
Setting up the launch configuration
https://aredel.com

Name the configuration and select the desired interpreter

Setting up PyCharm's launch configuration for Robot Robot Framework Support in PyCharm image from website www.aredel.com image from www.aredel.com website
Setting up the launch configuration
https://aredel.com

In the script field, click on file search

Setting up PyCharm's launch configuration for Robot Robot Framework Support in PyCharm image from website www.aredel.com image from www.aredel.com website
Setting up the launch configuration
https://aredel.com

Specify the path to robot.exe from your virtual environment

C:\Users\Andrei\robot\venv\Scripts\robot.exe


Or specify the path to run.py

C:/Users/Andrei/robot/venv/Lib/site-packages/robot/run.py

Setting up PyCharm's launch configuration for Robot Robot Framework Support in PyCharm image from website www.aredel.com image from www.aredel.com website
Setting up the launch configuration
https://aredel.com

In Script parameters specify the file before the test and click OK

Working directory will leave empty for now, we'll talk about it here

Setting up PyCharm's launch configuration for Robot Robot Framework Support in PyCharm image from website www.aredel.com image from www.aredel.com website
Setting up the launch configuration
https://aredel.com

The configuration name should appear in the top panel of the PyCharm window, where Current File used to be

Now, if the test does not import external libraries, it can be run with one click on the button

Setting up PyCharm's launch configuration for Robot Robot Framework Support in PyCharm image from website www.aredel.com image from www.aredel.com website
Setting up the launch configuration
https://aredel.com

Another example of setting up a configuration:

Open the desired .robot file and next to the start button select

Edit Configuration …

In PyCharm Community Edition I use the following settings

In PyCharm Professional, some fields have a different name or order.

Running tests with libraries

To proceed to configuring PyCharm to run robot tests, add all paths to libraries and resources to the interpreter.

File Settings Project Project Interpreter = ⌵ Show all Select the desired interpreter There are five icons in the right toolbar, click the folder tree icon + Select the directory OK

For example

C:\AutoTest\project\tests\robot\Libraries (added by user) C:\AutoTest\project\tests\robot\Resources (added by user) C:\AutoTest\project\tests\robot (added by user) C:\AutoTest\project\gen-py (added by user)

Robot Framework Support in PyCharm image from website www.aredel.com
Example of adding a directory to the interpreter path
aredel.com

Running tests with options

To use test run options in PyCharm, for example, --include they must be specified in the configuration

robot --include proto в PyCharm Robot Framework Support in PyCharm image from website www.aredel.com
robot --include proto в PyCharm
aredel.com

Working directory

Using Working directory, you can specify the directory from which tests will be run.

This can be useful if you decide to run tests intended for running in a CI/CD pipeline. For example, in Jenkins or GitHub Actions

These tests can rely on a specific directory on the runner. For example:

# common.py from robot.libraries.BuiltIn import BuiltIn _built_in = BuiltIn() def get_robot_variable(variable_name: str) -> Any: return _built_in.get_variable_value("${" + variable_name + "}") N_FTR_RSRCS: Path = Path(get_robot_variable("EXECDIR")).joinpath("xyz", "Resources", "n_ftr")

The code above assumes that the tests are run from a directory parent to xyz. It is not specified explicitly, but let's assume that it is autotests.

If the robot is located in the project structure so that it sees, for example, a directory parent to autotests as EXECDIR, then a space will appear in the path.

repo_name | `--autotests | |-- __init__.py | `-- xyz | |-- __init__.py | `-- Resources | `-- n_ftr `-- venv

The error that Python will return will look something like this:

FileNotFoundError: [Errno 2] No such file or directory

To avoid it, you need to explicitly specify the path to autotests in the Working directory

Working directory в PyCharm Robot Framework Support in PyCharm image from website www.aredel.com
Working directory в PyCharm
aredel.com
Related Articles
Robot Framework
Basics
RFBrowser
Set Variable
if else: conditionals
in: check if smth belongs to list
Loops
Change Variable Value
New Line
[Tags]
Collections: lists, dicts
JSON
Pass Argument to a Keyword
Evaluate
Robot in PyCharm
PyCharm

Search on this site

Subscribe to @aofeed channel for updates

Visit Channel

@aofeed

Feedback and Questions in Telegram

@aofeedchat