Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 36 ยท Getting Started

Installing Robot Framework and Running Your First Test

Install Robot Framework with pip in a virtual environment, write hello.robot, run it with the robot command and read the console output and exit code.

Installing Robot Framework takes one command, because it is an ordinary Python package. In this lesson you set up a clean environment, write a first test, run it and learn how to read what it prints. All commands here are read-only text on this site; run them on your own computer.

What you need

  • A recent Python 3 (check with python --version; Robot Framework 7 needs a currently supported Python 3 release).
  • pip, which comes with Python.
  • A text editor. Visual Studio Code with the "Robot Framework Language Server" extension, PyCharm with a Robot plugin, and RIDE (a dedicated editor) all work. Plain Notepad works too.

Create a virtual environment

A virtual environment keeps the packages of one project away from the others. Do this once per project:

Terminal
mkdir robot-demo
cd robot-demo
python -m venv .venv

# Windows (PowerShell)
.venv\Scripts\Activate.ps1
# macOS / Linux
source .venv/bin/activate

The prompt now starts with (.venv). On Windows the interpreter may be called py instead of python.

Install and check

Terminal
pip install robotframework
robot --version

robot --version prints a line like Robot Framework 7.x (Python 3.x on windows), with your real version numbers. If the command is not found, the environment is not activated, or the scripts folder is not on your PATH. A fallback that always works is python -m robot --version.

Pin the version for a team so everyone gets the same behavior:

Terminal
pip install "robotframework==7.3"
pip freeze > requirements.txt

(Use the version you tested with; the number above is only an example.)

Your first test

Create a file named hello.robot:

ROBOTFRAMEWORK
*** Test Cases ***
Say hello
    Log    Hello from Robot Framework!
    Log To Console    Hello on the console!

Check a sum
    ${result}=    Evaluate    40 + 2
    Should Be Equal As Integers    ${result}    42

The keywords Log, Log To Console, Evaluate and Should Be Equal As Integers all come from the built-in library, so nothing needs importing. Log writes to the log file; Log To Console writes to your terminal.

Run it:

Terminal
robot hello.robot

The console shows a table like this (abridged; the separator lines and paths differ on your machine):

TEXT
==============================================================================
Hello
==============================================================================
Say hello                                                             | PASS |
------------------------------------------------------------------------------
Check a sum                                                           | PASS |
------------------------------------------------------------------------------
Hello                                                                 | PASS |
2 tests, 2 passed, 0 failed
==============================================================================
Output:  ...\output.xml
Log:     ...\log.html
Report:  ...\report.html

Notice that the suite is named Hello: Robot builds the name from the file name by removing the extension, replacing underscores with spaces and capitalizing words. "Hello on the console!" is printed as the first test runs.

Open log.html and report.html in a browser. Click a test in the log to expand its steps, arguments and timings.

Exit codes

Robot's exit code tells scripts and CI what happened:

Code Meaning
0 All tests passed
1-249 That many tests failed
250 250 or more tests failed
251 Help or version information printed
252 Invalid test data or command line options
253 Execution stopped by the user (Ctrl+C)
255 Unexpected internal error

Skipped tests do not count as failures.

Stand-in 1: the console summary and exit code

The block below is not Robot Framework. It takes test results and prints a summary in the same spirit as Robot's console, computing the exit code with the rule from the table.

Python Stand-in: summary and exit code

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Stand-in 2: which files does Robot pick up?

When you run robot tests/, Robot walks the directory. A .robot file becomes a suite, a directory becomes a parent suite, and names starting with . or _ are skipped. .resource files are never run as tests. This stand-in applies those rules to a virtual file list.

Python Stand-in: suite discovery

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Real Robot also accepts .robot only by default; you can add extensions with --extension.

Common first-run problems

  • Two single spaces between a keyword and its argument. Log Hello looks fine, but the separator needs two or more spaces (or a tab), so Robot looks for a keyword called "Log Hello". Use Log Hello.
  • Test name not at the left edge. Test names must start in column 1; steps must be indented.
  • Missing section header. Without *** Test Cases ***, the file has no tests, and Robot reports an error.
  • Wrong Python. If robot and pip belong to different Pythons, install with python -m pip install robotframework and run with python -m robot.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which command installs Robot Framework?

    Robot Framework is a Python package published on PyPI under the name robotframework.
  2. 2. What does exit code 3 from the robot command mean?

    Codes 1 to 249 are the number of failed tests. Invalid options give 252.
  3. 3. What is the suite name for a file called user_login.robot?

    Robot removes the extension, turns underscores into spaces and capitalizes the words.
  4. 4. Which file is NOT run as a test suite?

    Resource files only hold keywords and variables to be imported by suites.

Summary

  • Install in a virtual environment with pip install robotframework; check with robot --version.
  • A .robot file with a *** Test Cases *** section is a complete suite; run it with robot file.robot.
  • The suite name comes from the file name; results appear in output.xml, log.html, report.html.
  • Exit code 0 means all passed; 1 to 250 counts failures; 251 to 255 signal usage or internal problems.
  • Keyword and argument separators need two or more spaces.

Next: Test Suites and Running Tests from the Command Line