---
title: Variables, resource files and user keywords | TestingBot
description: 'The first test works, but read it again as somebody who does not know
  the page: `id:my-text-id`, `name:my-select`, `css:button[type=submit]`. The test
  says…'
source_url:
  html: https://testingbot.com/resources/courses/robot-framework/variables-resources-and-keywords
  md: https://testingbot.com/resources/courses/robot-framework/variables-resources-and-keywords.md
---

Course

[Robot Framework Tutorial for Web Testing](https://testingbot.com/resources/courses/robot-framework)

Chapter 4 of 10

1. [1 Robot Framework Tutorial for Beginners](https://testingbot.com/resources/courses/robot-framework)
2. [2 Install Robot Framework in a Python virtual environment](https://testingbot.com/resources/courses/robot-framework/install-robot-framework)
3. [3 Your first Robot Framework test with SeleniumLibrary](https://testingbot.com/resources/courses/robot-framework/first-test-with-seleniumlibrary)
4. [4 Variables, resource files and user keywords](https://testingbot.com/resources/courses/robot-framework/variables-resources-and-keywords)
5. [5 Run Robot Framework tests on TestingBot](https://testingbot.com/resources/courses/robot-framework/run-robot-framework-on-testingbot)
6. [6 Robot Framework Browser library: Playwright on TestingBot](https://testingbot.com/resources/courses/robot-framework/browser-library-playwright)
7. [7 Data-driven tests with Robot Framework templates](https://testingbot.com/resources/courses/robot-framework/data-driven-tests-with-templates)
8. [8 Tags and parallel test runs with Pabot](https://testingbot.com/resources/courses/robot-framework/tags-and-parallel-runs-with-pabot)
9. [9 Robot Framework reports, CI and test status on TestingBot](https://testingbot.com/resources/courses/robot-framework/reports-ci-and-test-status)
10. [10 Knowledge check](https://testingbot.com/resources/courses/robot-framework/knowledge-check)

[Exit course](https://testingbot.com/resources/courses)

 Chapter 4 of 10 Beginner 6 min read 2 quick checks Updated Nov 2026 

# Variables, resource files and user keywords
On this page
1. [Variables](https://testingbot.com#variables)
2. [User keywords](https://testingbot.com#user-keywords)
3. [Resource files](https://testingbot.com#resource-files)
4. [Tests that read like behaviour](https://testingbot.com#tests-that-read-like-behaviour)
5. [Where Python keywords come in](https://testingbot.com#where-python-keywords-come-in)

The first test works, but read it again as somebody who does not know the page: `id:my-text-id`, `name:my-select`, `css:button[type=submit]`. The test says _how_ the page is built, not _what_ the user does. This chapter moves the how into keywords and resource files so the tests read like the behaviour they check. It is the Robot Framework version of the page object pattern; the [page object model course](https://testingbot.com/resources/courses/page-object-model) explains the idea in general.

## Variables[#](https://testingbot.com#variables)

Robot Framework has four kinds of variable syntax:

| Syntax | Kind | Example |
| --- | --- | --- |
| `${NAME}` | scalar: one value | `${BROWSER}` holds `chrome` |
| `@{NAME}` | list, expanded into separate arguments | `@{USERS}` |
| `&{NAME}` | dictionary, expanded into named arguments | `&{ENGINES}` in chapter 5 |
| `%{NAME}` | environment variable | `%{TB_KEY}`, or `%{TB_BUILD=robot-local}` with a default |

Define them in a ` ***Variables*** ` section. Names are case-insensitive and spaces and underscores are ignored, so `${FORM URL}` and `${form_url}` are the same variable. Uppercase for suite-level values is the common convention.

Any variable can be overridden from the command line, and the command line wins over the file:

```bash
robot --variable BROWSER:firefox tests/
```

That one switch is how the same suite runs on Chrome locally and on Safari in the cloud later, without touching a test. Robot Framework also sets a number of built-in variables you will use: `${TEST NAME}`, `${TEST STATUS}` (in a teardown), `${SUITE NAME}`, `${EMPTY}`, `${TRUE}` and `${FALSE}`.

## User keywords[#](https://testingbot.com#user-keywords)

A user keyword is defined in a ` ***Keywords*** ` section exactly like a test case, plus an optional `[Arguments]` line:

```robotframework
***Keywords***
Fill In The Form
    [Arguments] ${text} ${option}=Two
    Input Text id:my-text-id ${text}
    Select From List By Label name:my-select ${option}
```

`${option}=Two` gives the argument a default. Callers can pass it by position, `Fill In The Form Hello Three`, or by name, `Fill In The Form Hello option=Three`; the named form is easier to read when a keyword has more than one optional argument. A keyword can hand a value back with `RETURN`, and the caller stores it with `${value}= My Keyword`.

## Resource files[#](https://testingbot.com#resource-files)

A resource file is a `.resource` file with Settings, Variables and Keywords, but no test cases. Tests import it with `Resource` and can then use everything it defines. Split them by responsibility.

`resources/browser.resource` knows how to start and stop a browser:

```robotframework
***Settings***
Documentation Opens and closes the browser.
Library SeleniumLibrary timeout=10s

***Variables***
${BROWSER} chrome

***Keywords***
Open Test Browser
    [Arguments] ${url}
    Open Browser ${url} headless${BROWSER}
    Set Window Size 1920 1080

Close Test Browser
    Close All Browsers
```

`resources/web_form.resource` knows the web form, and nothing else:

```robotframework
***Settings***
Documentation Keywords for the Selenium practice web form.
Resource browser.resource

***Variables***
${FORM URL} https://www.selenium.dev/selenium/web/web-form.html

***Keywords***
Open The Web Form
    Open Test Browser ${FORM URL}
    Title Should Be Web form

Fill In The Form
    [Arguments] ${text} ${option}=Two
    Input Text id:my-text-id ${text}
    Select From List By Label name:my-select ${option}

Submit The Form
    Click Button css:button[type=submit]

Confirmation Should Be Shown
    Wait Until Page Contains Received!
    Title Should Be Web form - target page
```

Resource paths are resolved relative to the file that imports them, so `browser.resource` works from `web_form.resource` in the same folder, and tests one level down import `../resources/web_form.resource`.

The web form's submit button gets a new `id` and the locator has to change. With the structure above, how many files do you edit?

 One: `web_form.resource`, where `Submit The Form` is defined Every `.robot` file that submits the form `browser.resource`, because it imports SeleniumLibrary

Tests only call `Submit The Form`; the locator lives in one keyword. That is the point of the resource layer. `browser.resource` knows nothing about any particular page.

## Tests that read like behaviour[#](https://testingbot.com#tests-that-read-like-behaviour)

`tests/web_form.robot`:

```robotframework
***Settings***
Documentation The web form, written with user keywords.
Resource ../resources/web_form.resource
Test Setup Open The Web Form
Test Teardown Close Test Browser

***Test Cases***
Submitting The Form Shows A Confirmation
    Fill In The Form Robot Framework
    Submit The Form
    Confirmation Should Be Shown

The Dropdown Keeps The Chosen Option
    Fill In The Form anything option=Three
    List Selection Should Be name:my-select Three

Disabled Input Cannot Be Edited
    Element Should Be Disabled name:my-disabled
```

`Test Setup` and `Test Teardown` in Settings apply to every test in the file, so no test opens or closes a browser itself. Each test gets a fresh browser, which keeps tests independent: none of them depends on what a previous one left behind. That independence is what makes parallel runs in chapter 7 possible.

The last two tests still call SeleniumLibrary keywords directly. That is fine for one-off checks; once the same locator shows up in a second test, move it into the resource file.

```bash
robot --outputdir results tests/web_form.robot
robot --outputdir results --variable BROWSER:firefox tests/web_form.robot
```

```
Submitting The Form Shows A Confirmation | PASS |
------------------------------------------------------------------------------
The Dropdown Keeps The Chosen Option | PASS |
------------------------------------------------------------------------------
Disabled Input Cannot Be Edited | PASS |
------------------------------------------------------------------------------
Web Form :: The web form, written with user keywords. | PASS |
3 tests, 3 passed, 0 failed
```

Both commands pass: headless Chrome and headless Firefox, selected with nothing but a variable.

`browser.resource` sets `${BROWSER} chrome`. You run `robot --variable BROWSER:firefox tests/`. Which browser opens?

 Chrome, because the resource file is loaded after the command line is parsed Both, one after the other Neither: defining a variable in two places is an error Firefox: command-line variables override values from the Variables section

Variables given with `--variable` have higher priority than those in Variables sections, which is exactly what lets the file hold a sensible default while CI picks another browser.

## Where Python keywords come in[#](https://testingbot.com#where-python-keywords-come-in)

Some things are awkward in Robot Framework syntax: building nested data, calling an API, parsing a file. Any Python module can be imported as a library, and its functions become keywords: `def testingbot_options(...)` is called as `TestingBot Options`. The next chapter uses exactly that to build the capabilities for the TestingBot grid.

[Previous · Chapter 3 Your first Robot Framework test with SeleniumLibrary](https://testingbot.com/resources/courses/robot-framework/first-test-with-seleniumlibrary) [Next · Chapter 5 Run Robot Framework tests on TestingBot](https://testingbot.com/resources/courses/robot-framework/run-robot-framework-on-testingbot)

On this page

1. [Variables](https://testingbot.com#variables)
2. [User keywords](https://testingbot.com#user-keywords)
3. [Resource files](https://testingbot.com#resource-files)
4. [Tests that read like behaviour](https://testingbot.com#tests-that-read-like-behaviour)
5. [Where Python keywords come in](https://testingbot.com#where-python-keywords-come-in)

Certification

Earn the free, resume-worthy TestingBot Robot Framework Certification for this course.

[How it works](https://testingbot.com/resources/courses/robot-framework/certification)
