Table of Contents
- Introduction
- Data Driven Testing?
- Why use Data Driven Testing in Robot Framework?
- Methods of Data-Driven Testing in Robot Framework
- Method 1: Using FOR Loop
- Method 2: Using Test Template (Keyword-Driven DDT)
- Method 3: Reading Data from CSV & Excel Files
- Comparison Table: Which Method to Use?
- Why Need to Use Excel for Data-Driven Testing?
- Step-by-Step: Data-Driven Tests with Excel File
- Conclusion
- About Author
Introduction
The Robot Framework's support for data-driven testing is one of its most powerful features and is widely adopted in modern software automation testing services. Using this method, teams can run the same test case repeatedly with various input data sets, thereby lowering complexity, improving test coverage, and enhancing long-term maintainability.
Data Driven Testing?
Data-driven testing is a methodology where test logic is separated from test data, and the same test case is executed multiple times with different sets of inputs and expected outcomes.
Why use Data Driven Testing in Robot Framework?
- Reduces duplication in test cases
- Improves test coverage
- Makes tests more maintainable
- Easily integrates with external files (Excel, CSV, JSON)
Methods of Data-Driven Testing in Robot Framework
Using FOR Loops (Built-in)
Using Test Template
Using External Libraries (e.g., DataDriver, ExcelLibrary)
Method 1: Using FOR Loop
*** Settings ***
Library SeleniumLibrary
*** Variables ***
@{LOGIN_DATA} user1 pass1 user2 pass2 user3 pass3
*** Test Cases ***
Loop Through Credentials :
FOR ${i} IN RANGE 0 6 2
\ Log Username: ${LOGIN_DATA[${i}]}
\ Log Password: ${LOGIN_DATA[${i+1}]}
Method 2: Using Test Template (Keyword-Driven DDT)
This is Robot Framework's native way to do data-driven testing.
Step-by-Step Example: Login Testing
Step 1: Define the keyword
*** Keywords ***
Login With Credentials
[Arguments] ${username} ${password}
Log Trying to login with ${username}/${password}
# Add actual login steps here, like:
# Input Text id=username ${username}
# Input Text id=password ${password}
# Click Button id=login
Step 2: Create test cases using Test Template
*** Test Cases ***
Login Test With Multiple Data
[Template] Login With Credentials
user1 pass1
user2 pass2
user3 pass3
Method 3: Reading Data from CSV & Excel Files
Install:
pip install robotframework-datadriver
CSV File: login_data.csv
username,password user1,pass1 user2,pass2 user3,pass3
Test File:
*** Settings ***
Library SeleniumLibrary
Test Template Login With Credentials
Library DataDriver file=login_data.csv
*** Keywords ***
Login With Credentials
[Arguments] ${username} ${password}
Log Logging in with ${username} / ${password}
Comparison Table: Which Method to Use?
| Method | Best For | Ease of Use | Scalability | External File Support |
|---|---|---|---|---|
| FOR Loop | Quick loops | Easy | Low | No |
| Test Template | Clean DDT with small data | Easy | Medium | No |
| DataDriver (CSV/Excel) | Large or dynamic test data | Medium | High | Yes |
| ExcelLibrary / Custom | Flexible and programmable logic | Medium | High | Yes |
Why Need to Use Excel for Data-Driven Testing?
Using Excel is a popular tool for organising structured data, so it makes sense to want to incorporate it into your automated framework for data-driven testing. Fortunately, Robot Framework uses RPA and other APIs to make this simple. ExcelLibrary or Excel.Files.
- Storing test input/output data
- Keeping test data manageable and readable
- Allowing non-technical users to contribute to test scenarios
Robot Framework supports Excel via multiple libraries that let you read, write, and loop through data row by row.
Step-by-Step: Data-Driven Tests with Excel File
Step 1: Install Required Library
pip install rpaframework
Step 2: Prepare your Excel file
| username | password |
|---|---|
| user1 | pass1 |
| user2 | pass2 |
| user3 | pass3 |
Step 3: Create Your .robot Test File
*** Settings ***
Library RPA.Excel.Files
Library SeleniumLibrary
*** Variables ***
${EXCEL_PATH} LoginData.xlsx
*** Test Cases ***
Data-Driven Login Test
Open Workbook ${EXCEL_PATH}
${rows}= Read Worksheet As Table header=True
FOR ${row} IN @{rows}
${username}= Set Variable ${row}[username]
${password}= Set Variable ${row}[password]
Log Testing login with ${username} / ${password}
# Here you would add your actual login steps
# Open Browser https://example.com Chrome
# Input Text id=username ${username}
# Input Text id=password ${password}
# Click Button id=login
# Close Browser
END
Close Workbook
Conclusion
Testing process becomes more collaborative and scalable when you integrate Excel into Robot Framework projects, bridging the gap between automated and manual testing workflows. To make your tests even more dynamic and adaptable, start small with Test Templates and then investigate external data sources like CSV or Excel as your test data develops.
