Tutorial

Robot Framework Tutorial: Write and Run Your First Test Suite

Ascending training steps leading to a completed check

Robot Framework tutorial content often jumps straight into browser automation, but the fastest way to learn is to start with a tiny suite that runs in seconds. This walkthrough covers installation, file structure, keywords, variables and reports, giving you a working mental model before you add any external libraries.

What You Need Before You Start

Robot Framework runs on Python, so the only hard requirement is a Python 3 interpreter supported by the release you install. A code editor with syntax highlighting makes the tabular format much easier to read, and a terminal is needed to run the robot command and open the generated results.

  • Python 3 available on your PATH
  • pip for installing packages from PyPI
  • A project folder and, ideally, a virtual environment
  • Any text editor; IDE extensions add completion and navigation

Installing Robot Framework

Create a virtual environment inside your project folder, activate it and install the package with pip. Keeping each project in its own environment prevents version clashes between libraries and makes it simple to reproduce the setup on a colleague’s machine or a CI runner.

python -m venv .venv
source .venv/bin/activate        # Windows: .venv\Scripts\activate
python -m pip install robotframework
robot --version

If robot --version prints a version string, the installation worked. Detailed platform notes, including PATH fixes for Windows, are covered in the installation walkthrough for Windows, macOS and Linux.

Understanding the File Structure

Test data lives in files with the .robot extension. Each file is a test suite, and a folder of .robot files becomes a parent suite automatically. Inside a file, content is split into sections that start with three asterisks on both sides of the section name.

SectionPurpose
*** Settings ***Imports libraries and resources, sets documentation, setups and teardowns
*** Variables ***Defines reusable values such as URLs, timeouts and user names
*** Test Cases ***Holds the executable tests, each built from keyword calls
*** Keywords ***Creates user keywords that combine other keywords into reusable steps

Separators and Indentation

Cells are separated by two or more spaces, and four spaces is the common convention. Test case and keyword names start at the beginning of a line, while their steps are indented. A single space is treated as part of a value, which is why “Should Be Equal” works as one keyword name.

Writing Your First Test Suite

Create a file called first_suite.robot and add the following content. It uses only BuiltIn keywords, which are always available, so no extra library installation is required for this example.

*** Settings ***
Documentation    My first suite.

*** Variables ***
${GREETING}      Hello, Robot

*** Test Cases ***
Greeting Is Correct
    ${text}=    Set Variable    Hello, Robot
    Should Be Equal    ${text}    ${GREETING}
    Log    Test finished

Number Comparison Works
    ${sum}=    Evaluate    2 + 3
    Should Be Equal As Integers    ${sum}    5

Each indented line calls a keyword followed by its arguments. Set Variable returns a value that is stored in ${text}, and Should Be Equal fails the test if its two arguments differ. More patterns like these appear in the collection of practical Robot Framework examples.

Running Tests and Reading Results

Run the suite from the project folder with robot first_suite.robot. The console shows each test with a PASS or FAIL status, followed by a summary line and the paths of three result files written to the current directory.

  • output.xml contains machine-readable results for tools and merging
  • log.html shows every keyword, argument, message and timing
  • report.html gives a high-level overview with statistics by tag and suite

Open log.html in a browser whenever a test fails. Expanding the failing test shows the exact keyword that raised the error and the message it produced, which is usually enough to locate the problem quickly.

Creating User Keywords

User keywords keep tests short by moving repeated steps into named building blocks. They are defined in the Keywords section, can accept arguments and can return values, so a test reads like a list of business actions rather than low-level instructions.

*** Keywords ***
Greeting Should Match
    [Arguments]    ${actual}
    Should Be Equal    ${actual}    ${GREETING}

Once a project grows, move shared keywords into a .resource file and import it with the Resource setting. The deeper explanation of built-in, library and user keywords is available in the Robot Framework keywords overview.

Tags, Setup and Teardown

Tags label tests so you can run subsets with --include or --exclude. Setup and teardown keywords prepare and clean the environment, and a teardown still runs when the test fails, which makes it the right place for closing browsers or deleting temporary data.

Greeting Is Correct
    [Tags]    smoke
    [Setup]    Log    Preparing
    Greeting Should Match    Hello, Robot
    [Teardown]    Log    Cleaning up

Next Steps After the Basics

With the core syntax in place, most learners move to a real application. Web testers usually continue with Robot Framework Selenium, while developers often learn how to write custom keywords in Python libraries for logic that would be awkward in test data.

  • Browser automation with SeleniumLibrary or Browser library
  • API checks with RequestsLibrary
  • Data-driven tests with test templates
  • Running suites in a CI pipeline and archiving reports

Frequently Asked Questions

How long does it take to learn Robot Framework?

Basic syntax can be learned in a few hours because tests are mostly keyword calls. Becoming productive with libraries, resource files and project structure usually takes a few weeks of regular use on a real project.

Do I need programming experience for this tutorial?

No programming experience is required to write and run tests with existing keywords. Python knowledge becomes useful later, when you want to create custom libraries or handle complex logic outside the test data.

Can I use Robot Framework without a browser?

Yes. The examples in this tutorial use only BuiltIn keywords and run entirely in the terminal. Browser libraries are optional and only needed for web user interface testing.

After the first successful run, deliberately change an expected value and run the same suite again. Open the HTML log, expand the failing keyword and compare the reported actual and expected values. Restore the original expectation and confirm the suite passes. Repeat this exercise when introducing a new library so you understand what evidence its keywords leave in the log when an assertion fails or setup cannot finish. Save both logs for your initial review.

Conclusion

Robot Framework tutorial steps like these give you a solid base: install with pip, structure suites into sections, write tests from keywords, run them with robot and read the log. Practise by turning a few manual checks from your own project into small suites, then add libraries as real needs appear.