---
title: Data-driven tests with Robot Framework templates
description: 'Many tests are the same steps with different data: a login form with
  a wrong user, a wrong password, an empty field. Writing each one out repeats the
  steps;…'
source_url:
  html: https://testingbot.com/resources/courses/robot-framework/data-driven-tests-with-templates
  md: https://testingbot.com/resources/courses/robot-framework/data-driven-tests-with-templates.md
---

Course

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

Chapter 7 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 7 of 10 Beginner 6 min read 2 quick checks Updated Nov 2026 

# Data-driven tests with Robot Framework templates
On this page
1. [The keyword that does the work](https://testingbot.com#the-keyword-that-does-the-work)
2. [The template](https://testingbot.com#the-template)
3. [Template or FOR loop?](https://testingbot.com#template-or-for-loop)
4. [When the data lives outside the suite](https://testingbot.com#when-the-data-lives-outside-the-suite)

Many tests are the same steps with different data: a login form with a wrong user, a wrong password, an empty field. Writing each one out repeats the steps; looping over the data in one test hides which case failed. Robot Framework's **test templates** give you one keyword for the steps and one table row per case, and every row is its own test in the report.

The examples use the practice [login page](https://the-internet.herokuapp.com/login) of The Internet. Its valid credentials, `tomsmith` and `SuperSecretPassword!`, are printed on the page itself; anything else shows a red message saying whether the username or the password was wrong.

## The keyword that does the work[#](https://testingbot.com#the-keyword-that-does-the-work)

`resources/login.resource`:

```robotframework
***Settings***
Documentation Keywords for the practice login page.
Resource browser.resource

***Variables***
${LOGIN URL} https://the-internet.herokuapp.com/login

***Keywords***
Log In As
    [Arguments] ${username} ${password}
    Input Text id:username ${username}
    Input Password id:password ${password}
    Click Button css:button[type=submit]

Login Should Fail With
    [Arguments] ${username} ${password} ${message}
    Log In As ${username} ${password}
    Wait Until Element Contains id:flash ${message}
```

`Input Password` does the same as `Input Text` but does not write the value to the log, so a real password never ends up in `log.html`. `Wait Until Element Contains` is the fix from chapter 2: the message only exists after the page has reloaded.

## The template[#](https://testingbot.com#the-template)

`tests/login.robot`:

```robotframework
***Settings***
Documentation Data-driven login checks with a test template.
Resource ../resources/login.resource
Test Setup Open Test Browser ${LOGIN URL}
Test Teardown Close Test Browser
Test Template Login Should Fail With

***Test Cases*** USERNAME PASSWORD MESSAGE
Unknown User nobody SuperSecretPassword! Your username is invalid!
Wrong Password tomsmith wrong Your password is invalid!
Empty Username ${EMPTY} SuperSecretPassword! Your username is invalid!
Username Is Case Sensitive TOMSMITH SuperSecretPassword! Your username is invalid!

***Test Cases***
Valid Login Reaches The Secure Area
    [Template] NONE
    Log In As tomsmith SuperSecretPassword!
    Wait Until Element Contains id:flash You logged into a secure area!
```

How it works:

- **`Test Template Login Should Fail With`** makes every test in the file call that keyword, with the test's cells as its arguments. A row is therefore a complete test: name, then username, password and expected message.
- **The extra words in the header line** (`USERNAME`, `PASSWORD`, `MESSAGE`) are ignored by Robot Framework. They are column titles for the human reader, and they are what makes the table readable.
- **`${EMPTY}`** passes an empty string. A blank cell would be ignored rather than passed as an argument, which shifts every value one column to the left.
- **`[Template] NONE`** switches the template off for a test that needs ordinary steps. A file may have more than one Test Cases section, which keeps the happy path visually apart from the table.

Setup and teardown still apply to every row, so each case gets its own fresh browser: one case can never leave the next one logged in.

```bash
robot --outputdir results tests/login.robot
```

```
Unknown User | PASS |
------------------------------------------------------------------------------
Wrong Password | PASS |
------------------------------------------------------------------------------
Empty Username | PASS |
------------------------------------------------------------------------------
Username Is Case Sensitive | PASS |
------------------------------------------------------------------------------
Valid Login Reaches The Secure Area | PASS |
------------------------------------------------------------------------------
Login :: Data-driven login checks with a test template. | PASS |
5 tests, 5 passed, 0 failed
```

The same file ran unchanged on TestingBot, all five tests passing on Safari on macOS Sequoia (`--variable GRID:True --variable BROWSER:safari --variable PLATFORM:SEQUOIA`) and on Edge on Windows 11.

A new row `Empty Password tomsmith Your password is invalid!` (with an empty cell for the password) fails with "expected 3 arguments, got 2". Why?

 Templates cannot test empty values Empty cells are ignored, so the row passes only two arguments; write `${EMPTY}` in the password column The column header line needs a type for each column

Robot Framework separates cells by runs of spaces, so an empty cell simply disappears. `${EMPTY}` is the explicit empty string. Header words are only labels and have no types.

## Template or FOR loop?[#](https://testingbot.com#template-or-for-loop)

You could write the same checks as one test with a `FOR` loop over a list. The difference shows up when something fails:

| | Template, one row per test | One test with a FOR loop |
| --- | --- | --- |
| Report | one line per case, named after it | one line for all cases |
| After a failing case | the other cases still run | the loop stops at the first failure |
| Rerun one case | `robot --test "Wrong Password"` | not possible |
| Parallel runs | each row can run in its own process (chapter 7) | the loop runs as one unit |

Use a loop for steps _inside_ a test (fill five fields, check five rows); use a template when every data set is a separate case you want reported on its own.

A suite checks 40 discount codes in one test with a FOR loop. Code 7 is broken, and the report only says the test failed. What change gives you a result per code?

 Add `Log` statements inside the loop Wrap the loop body in `Run Keyword And Continue On Failure` Turn it into a templated test file with one row per code

Continuing on failure would at least run all codes, but the report would still have one test with a list of errors, and a single code could not be rerun or run in parallel. One row per code makes each its own test.

## When the data lives outside the suite[#](https://testingbot.com#when-the-data-lives-outside-the-suite)

A table in the `.robot` file is right for a handful of cases that change with the tests. When the data comes from a spreadsheet maintained by someone else, or there are hundreds of rows, the community library **DataDriver** (`robotframework-datadriver`) generates one test per row of a CSV or Excel file using the same template keyword. Keep the keyword exactly as it is here; only where the rows come from changes.

[Previous · Chapter 6 Robot Framework Browser library: Playwright on TestingBot](https://testingbot.com/resources/courses/robot-framework/browser-library-playwright) [Next · Chapter 8 Tags and parallel test runs with Pabot](https://testingbot.com/resources/courses/robot-framework/tags-and-parallel-runs-with-pabot)

On this page

1. [The keyword that does the work](https://testingbot.com#the-keyword-that-does-the-work)
2. [The template](https://testingbot.com#the-template)
3. [Template or FOR loop?](https://testingbot.com#template-or-for-loop)
4. [When the data lives outside the suite](https://testingbot.com#when-the-data-lives-outside-the-suite)

Certification

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

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