TL;DR
- Robot Framework uses keyword-driven approach — readable tests without coding
- Tests written in tabular format (plain text, .robot files)
- SeleniumLibrary for web testing, RequestsLibrary for APIs
- Create custom keywords to encapsulate complex logic
- Built-in reporting and CI/CD integration
Best for: Teams with mixed technical skills, acceptance testing, RPA Skip if: Need maximum flexibility (use Python/pytest directly) Reading time: 15 minutes
Your team includes manual testers who don’t code. Management wants readable test reports. Tests need to be maintainable by non-developers.
Robot Framework solves this. Tests are written in plain English keywords. Anyone can read them. Developers can extend them. Reports are automatically generated.
This tutorial covers Robot Framework from setup to CI/CD integration — everything for keyword-driven test automation.
What is Robot Framework?
Robot Framework is a generic open-source automation framework for acceptance testing, acceptance test-driven development (ATDD), and robotic process automation (RPA). It uses a keyword-driven approach where tests are written in a human-readable tabular format.
Why Robot Framework:
- Readable syntax — tests look like natural language
- Easy to learn — non-programmers can write tests
- Extensible — Python/Java libraries extend functionality
- Built-in reporting — HTML reports generated automatically
- Large ecosystem — libraries for web, API, mobile, desktop
Setup
Installation
# Install Robot Framework
pip install robotframework
# Install SeleniumLibrary for web testing
pip install robotframework-seleniumlibrary
# Install RequestsLibrary for API testing
pip install robotframework-requests
# Install Browser Library (Playwright-based alternative)
pip install robotframework-browser
rfbrowser init
# Verify installation
robot --version
Project Structure
project/
├── tests/
│ ├── login_tests.robot
│ ├── api_tests.robot
│ └── __init__.robot
├── resources/
│ ├── keywords.robot
│ ├── variables.robot
│ └── pages/
│ └── login_page.robot
├── results/
└── requirements.txt
Basic Syntax
First Test
*** Settings ***
Library SeleniumLibrary
*** Variables ***
${BROWSER} chrome
${URL} https://example.com
*** Test Cases ***
User Can Open Homepage
Open Browser ${URL} ${BROWSER}
Title Should Be Example Domain
Close Browser
User Can Search For Products
Open Browser ${URL} ${BROWSER}
Input Text id=search robot framework
Click Button id=search-btn
Page Should Contain Results
Close Browser
Sections Explained
| Section | Purpose |
|---|---|
*** Settings *** | Libraries, resources, setup/teardown |
*** Variables *** | Test data and configuration |
*** Test Cases *** | Actual test scenarios |
*** Keywords *** | Custom reusable keywords |
SeleniumLibrary for Web Testing
Common Keywords
*** Settings ***
Library SeleniumLibrary
*** Test Cases ***
Web Interaction Examples
# Navigation
Open Browser https://example.com chrome
Go To https://example.com/login
# Input
Input Text id=username testuser
Input Password id=password secret123
# Clicking
Click Button id=submit
Click Element xpath=//a[@class='link']
Click Link Home
# Verification
Page Should Contain Welcome
Page Should Contain Element id=dashboard
Element Should Be Visible class=success-message
Element Text Should Be id=greeting Hello User
# Waiting
Wait Until Element Is Visible id=loading timeout=10s
Wait Until Page Contains Dashboard
# Getting values
${text}= Get Text id=message
${value}= Get Value id=input-field
${attr}= Get Element Attribute id=link href
Close Browser
Setup and Teardown
*** Settings ***
Library SeleniumLibrary
Suite Setup Open Browser ${URL} ${BROWSER}
Suite Teardown Close All Browsers
Test Setup Go To ${URL}
Test Teardown Capture Page Screenshot
*** Variables ***
${URL} https://example.com
${BROWSER} chrome
*** Test Cases ***
Test One
# Browser already open from Suite Setup
Page Should Contain Welcome
Test Two
# Fresh page load from Test Setup
Click Link About
Page Should Contain About Us
Custom Keywords
Creating Keywords
*** Settings ***
Library SeleniumLibrary
*** Keywords ***
Login With Credentials
[Arguments] ${username} ${password}
Input Text id=username ${username}
Input Password id=password ${password}
Click Button id=login-btn
Wait Until Page Contains Element id=dashboard
Logout
Click Element id=user-menu
Click Link Logout
Wait Until Page Contains Login
Verify Dashboard Loaded
Page Should Contain Element id=dashboard
Element Should Be Visible id=welcome-message
Page Should Not Contain Error
*** Test Cases ***
Successful Login
Open Browser https://example.com/login chrome
Login With Credentials user@example.com password123
Verify Dashboard Loaded
Logout
Close Browser
Keywords with Return Values
*** Keywords ***
Get User Name From Dashboard
${name}= Get Text id=user-name
[Return] ${name}
Create User And Get ID
[Arguments] ${name} ${email}
Input Text id=name ${name}
Input Text id=email ${email}
Click Button id=create
Wait Until Page Contains Element id=user-id
${id}= Get Text id=user-id
[Return] ${id}
*** Test Cases ***
Verify User Creation
Open Browser ${URL} chrome
${user_id}= Create User And Get ID John Doe john@example.com
Should Not Be Empty ${user_id}
Log Created user with ID: ${user_id}
Close Browser
Page Object Pattern
Page Resource File
# resources/pages/login_page.robot
*** Settings ***
Library SeleniumLibrary
*** Variables ***
${LOGIN_URL} https://example.com/login
${USERNAME_FIELD} id=username
${PASSWORD_FIELD} id=password
${LOGIN_BUTTON} id=login-btn
${ERROR_MESSAGE} class=error-msg
${DASHBOARD} id=dashboard
*** Keywords ***
Navigate To Login Page
Go To ${LOGIN_URL}
Enter Username
[Arguments] ${username}
Input Text ${USERNAME_FIELD} ${username}
Enter Password
[Arguments] ${password}
Input Password ${PASSWORD_FIELD} ${password}
Click Login Button
Click Button ${LOGIN_BUTTON}
Login Should Succeed
Wait Until Page Contains Element ${DASHBOARD} timeout=10s
Login Should Fail With Message
[Arguments] ${expected_message}
Element Should Be Visible ${ERROR_MESSAGE}
Element Text Should Be ${ERROR_MESSAGE} ${expected_message}
Login As User
[Arguments] ${username} ${password}
Navigate To Login Page
Enter Username ${username}
Enter Password ${password}
Click Login Button
Using Page Objects
*** Settings ***
Library SeleniumLibrary
Resource resources/pages/login_page.robot
Suite Setup Open Browser ${URL} ${BROWSER}
Suite Teardown Close All Browsers
*** Variables ***
${URL} https://example.com
${BROWSER} chrome
*** Test Cases ***
Valid Login
Login As User user@example.com password123
Login Should Succeed
Invalid Password
Login As User user@example.com wrongpassword
Login Should Fail With Message Invalid credentials
Data-Driven Testing
Test Templates
*** Settings ***
Library SeleniumLibrary
Test Template Login Should Fail For Invalid Credentials
*** Test Cases *** USERNAME PASSWORD ERROR
Empty Username ${EMPTY} password123 Username required
Empty Password user@example.com ${EMPTY} Password required
Invalid Email Format invalid-email password123 Invalid email format
Wrong Password user@example.com wrongpass Invalid credentials
Locked Account locked@example.com password123 Account is locked
*** Keywords ***
Login Should Fail For Invalid Credentials
[Arguments] ${username} ${password} ${expected_error}
Open Browser https://example.com/login chrome
Input Text id=username ${username}
Input Password id=password ${password}
Click Button id=login
Element Text Should Be class=error ${expected_error}
Close Browser
External Data Files
*** Settings ***
Library SeleniumLibrary
Library DataDriver file=test_data.csv
Test Template Verify Login
*** Test Cases ***
Login Test ${username} ${password} ${expected}
*** Keywords ***
Verify Login
[Arguments] ${username} ${password} ${expected}
Open Browser https://example.com/login chrome
Input Text id=username ${username}
Input Password id=password ${password}
Click Button id=login
Run Keyword If '${expected}'=='success' Page Should Contain Dashboard
... ELSE Page Should Contain Error
Close Browser
API Testing
*** Settings ***
Library RequestsLibrary
Library Collections
*** Variables ***
${BASE_URL} https://jsonplaceholder.typicode.com
*** Test Cases ***
Get All Users
Create Session api ${BASE_URL}
${response}= GET On Session api /users
Status Should Be 200 ${response}
${users}= Set Variable ${response.json()}
Length Should Be ${users} 10
Create New Post
Create Session api ${BASE_URL}
${body}= Create Dictionary title=Test Post body=Content userId=1
${response}= POST On Session api /posts json=${body}
Status Should Be 201 ${response}
${post}= Set Variable ${response.json()}
Should Be Equal ${post['title']} Test Post
Update Post
Create Session api ${BASE_URL}
${body}= Create Dictionary title=Updated Title
${response}= PATCH On Session api /posts/1 json=${body}
Status Should Be 200 ${response}
Delete Post
Create Session api ${BASE_URL}
${response}= DELETE On Session api /posts/1
Status Should Be 200 ${response}
CI/CD Integration
GitHub Actions
name: Robot Framework Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
pip install robotframework robotframework-seleniumlibrary
pip install webdriver-manager
- name: Install Chrome
uses: browser-actions/setup-chrome@latest
- name: Run tests
run: |
robot --outputdir results tests/
- name: Upload results
uses: actions/upload-artifact@v4
if: always()
with:
name: robot-results
path: results/
Running Tests
# Run all tests
robot tests/
# Run specific test file
robot tests/login_tests.robot
# Run with tags
robot --include smoke tests/
robot --exclude slow tests/
# Run with variables
robot --variable BROWSER:firefox --variable URL:https://staging.example.com tests/
# Output to specific directory
robot --outputdir results tests/
Robot Framework with AI Assistance
AI tools can help write and maintain Robot Framework tests.
What AI does well:
- Generate keywords from user stories
- Create test data variations
- Convert manual test cases to Robot syntax
- Suggest library keywords
What still needs humans:
- Understanding business requirements
- Designing test architecture
- Debugging complex failures
- Maintaining page objects
FAQ
What is Robot Framework?
Robot Framework is a Python-based open-source automation framework that uses a keyword-driven approach. Tests are written in a readable tabular format that looks like natural language, making them accessible to non-programmers. It supports web, API, mobile, and desktop testing through various libraries.
Is Robot Framework free?
Yes, Robot Framework is completely free and open-source under the Apache 2.0 license. All standard libraries (SeleniumLibrary, RequestsLibrary, etc.) are also free. There are no paid versions or enterprise features — everything is available at no cost.
Robot Framework vs Selenium — what’s the difference?
Robot Framework is a test automation framework that provides the structure and syntax for writing tests. Selenium is a browser automation library. Robot Framework uses SeleniumLibrary (a wrapper around Selenium) to perform web browser automation. Think of Robot Framework as the test framework and Selenium as the browser driver.
Can Robot Framework test APIs?
Yes, Robot Framework can test REST APIs using RequestsLibrary. You can make HTTP requests (GET, POST, PUT, DELETE), verify response status codes, parse JSON responses, and validate data. For SOAP APIs, you can use SudsLibrary or similar.
Official Resources
See Also
- Selenium Tutorial - Browser automation fundamentals
- API Testing Guide - REST API testing
- Cucumber BDD Tutorial - Behavior-driven development
- Python Testing Guide - Python test automation
