Robot Framework Fundamental Concepts

In this section, we are going to see some fundamental concepts on Robot Framework. 

This section explains the core concepts of Robot Framework:
Settings, Test Cases, Keywords, Variables, Test Suites, Tags, Documentation, and Metadata.

1. Settings

The *** Settings *** section is the first and most important part of any .robot file.
It defines configurations, imports, and metadata that apply to the entire test suite.

You can use this section to:

     - Import external libraries like SeleniumLibrary
     - Add resource files
     - Define suite-level setup or teardown
     - Provide metadata (author, version, environment)

Example: 

*** Settings ***
Library           SeleniumLibrary
Resource          common_keywords.robot
Suite Setup       Open Browser    https://www.example.com    chrome
Suite Teardown    Close Browser
Metadata          Author          Tester


The information in the Metadata section appears in the generated HTML report after test execution.

2. Test Cases

A test case in Robot Framework represents a single automated scenario (similar to one manual test case).

All test cases are written under the section: *** Test Cases ***

Example Test Cases

*** Test Cases ***
Verify Google Title
    Open Browser    https://www.google.com    chrome
    Title Should Be    Google
    Close Browser


Explanation:

This test opens the Chrome browser, navigates to Google, checks if the page title is “Google,” and then closes the browser.

Each line inside a test case uses keywords, which represent individual action steps.

3. Keywords

Keywords are the building blocks of Robot Framework.

They describe what actions to perform, such as clicking a button, typing text, or verifying a condition.

There are two types of keywords:

a) Built-in Keywords

Provided by Robot Framework itself or by external libraries (like SeleniumLibrary, RequestsLibrary, etc.).

Log    Hello World
Should Be Equal    5    5
Sleep    2s


Explanation:

Log prints a message in the report.
Should Be Equal verifies that two values are the same.
Sleep 2s pauses the test for 2 seconds.

b) User-Defined Keywords

Created by users to group repeated actions and make tests reusable and readable.

Example:

*** Keywords ***
Open Google
    Open Browser    https://www.google.com    chrome
    Title Should Be    Google
    Close Browser
*** Test Cases ***
Verify Google Page
    Open Google


Explanation:

Here, Open Google is a custom keyword (like a function in programming).
You can reuse it across multiple test cases.

4. Variables

Variables help avoid hardcoding values and make tests easier to maintain.

All variables are written under the section:

*** Variables ***


Common variable types:

Type

Example

Description

Scalar

${URL}

Single value

List

@{BROWSERS}

Multiple values

Dictionary

&{USER}

Key-value pairs


Example: 

*** Variables ***
${URL}          https://www.example.com/login
${BROWSER}      chrome
@{CREDENTIALS}  testUser    testPass123
&{USER}         username=testUser    password=testPass123
*** Test Cases ***
Use Variables for Login
    Open Browser    ${URL}    ${BROWSER}
    Input Text      name=username    ${USER.username}
    Input Text      name=password    ${USER.password}
    Click Button    name=login
    Title Should Be Dashboard
    Close Browser


5. Tags

Tags help categorize and filter your tests.
They’re written right below the test name using [Tags].

Example: 

*** Test Cases ***
Verify Login
    [Tags]    smoke    regression
    Log    Checking login functionality


You can run specific tagged tests:

robot --include smoke tests/
robot --exclude regression tests/


This is useful in CI/CD pipelines or selective test execution.

6. Documentation

You can describe what a test or keyword does using [Documentation]. This improves readability and helps others understand the purpose of each test.

Example (Test Case level):

*** Test Cases ***
Verify Login Functionality
    [Documentation]    This test validates login with valid credentials.
    Open Browser    https://www.example.com/login    chrome
    Input Text    name=username    testUser
    Input Text    name=password    testPass123
    Click Button    name=login
    Title Should Be    Dashboard
    Close Browser


Example (Keyword level):

*** Keywords ***
Perform Login
    [Documentation]    Opens the login page and logs in using valid credentials.
    Open Browser    https://www.example.com/login    chrome
    Input Text    name=username    testUser
    Input Text    name=password    testPass123
    Click Button    name=login

7. Metadata

Metadata adds extra information about a suite, such as the author, version, or environment.

It is defined under the section:

*** Settings ***


Example: 

*** Settings ***
Metadata    Author    TESTER
Metadata    Version   1.0
Metadata    Environment   QA


These details appear in the HTML report after test execution.

Summary Table

Concept

Purpose

Example Section

Test Case

Defines a single scenario to test

*** Test Cases ***

Keyword

Describes Steps or reusable actions

*** Keywords ***

Variable

Stores data for reuse

*** Variables ***

Test Suite

Group Test Cases Logically

.robot file or folder

Tag

Categorize and filter tests

[Tags] smoke

Documentation

Add readable explanation

[Documentation] ...

Metadata

Add suite-level info

Metadata Author Tester

 

 

Related Tutorials