Robot Framework is a popular open-source test automation framework that uses a simple syntax for writing tests in plain text. It supports acceptance testing, acceptance test-driven development (ATDD), and robotic process automation (RPA). Robot Framework is keyword-driven and extensible through libraries.
π Table of Contents
- What is Robot Framework?
- Installing Robot Framework
- Test Structure and Syntax
- UI Testing Example (SeleniumLibrary)
- API Testing Example (RequestsLibrary)
- Directory Structure
- Run Tests and Reports
- CI/CD with GitHub Actions
- CI/CD with Jenkins
- Custom Libraries with Python
- Parallel Execution with Pabot
- Allure Report Integration
- Data-Driven Testing with Templates
- Dockerized Robot Framework
- Debugging and Logging Tips
- Security and Secrets Management
- Comparison With Other Tools
- Best Practices
- Going Further
Conclusion
Further Resources
1. What is Robot Framework?
Robot Framework is a generic test automation framework ideal for:
- Acceptance Testing
- API Testing
- UI Testing
- Regression Testing
- Robotic Process Automation (RPA)
It is Python-based and supports libraries written in Python or Java.
β Key Features:
- Keyword-driven and data-driven testing
- Rich ecosystem of libraries (SeleniumLibrary, RequestsLibrary, etc.)
- Human-readable syntax (plain text, reStructuredText, Markdown)
- Can be extended via custom Python libraries
- CLI and IDE integration (e.g., VS Code with Robot Framework Language Server)
2. Installing Robot Framework
You can install Robot Framework and essential libraries using pip
:
pip install robotframework
pip install robotframework-seleniumlibrary
pip install robotframework-requests
For browser automation:
pip install robotframework-browser
rfbrowser init
You can also use pipx
or Docker for isolation:
pipx install robotframework
3. Test Structure and Syntax
A typical Robot Framework test suite is a .robot
file with the following sections:
*** Settings ***
Library SeleniumLibrary
*** Variables ***
${URL} https://example.com
*** Test Cases ***
Open Homepage
Open Browser ${URL} chrome
Page Should Contain Welcome
Close Browser
*** Keywords ***
Login As User
Input Text username user1
Input Password password 1234
Click Button login
β
Use the Gherkin-style (Given
, When
, Then
) format with optional support.
4. UI Testing Example (SeleniumLibrary)
*** Settings ***
Library SeleniumLibrary
*** Variables ***
${URL} https://example.com
*** Test Cases ***
User Can Login
Open Browser ${URL} chrome
Input Text id=username testuser
Input Password id=password password123
Click Button id=login
Page Should Contain Dashboard
Close Browser
π§ Tip: Use id
, name
, or XPath
selectors to locate elements.
5. API Testing Example (RequestsLibrary)
*** Settings ***
Library RequestsLibrary
*** Variables ***
${API_URL} https://api.example.com
*** Test Cases ***
Get User Info
Create Session api ${API_URL}
GET api /users/1
Status Should Be 200
Response Should Contain "username"
You can parse JSON with Evaluate
or BuiltIn
functions.
6. Directory Structure
robot-tests/
βββ tests/
β βββ ui/
β β βββ login.robot
β βββ api/
β β βββ user.robot
βββ resources/
β βββ keywords.robot
βββ variables/
β βββ global_variables.robot
βββ output/
β βββ (results go here)
βββ requirements.txt
β Separate tests, resources, and variables for maintainability.
7. Run Tests and Reports
Run tests with:
robot tests/ui/login.robot
This generates:
output.xml
report.html
log.html
You can re-run failed tests:
rebot --rerunfailed output.xml --output rerun.xml tests/
8. CI/CD with GitHub Actions
.github/workflows/robot.yml
:
name: Run Robot Framework Tests
on:
push:
branches: [main]
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
pip install -r requirements.txt
rfbrowser init
- name: Run Robot Framework tests
run: |
robot tests/
- name: Upload report
uses: actions/upload-artifact@v3
with:
name: robot-report
path: report.html
9. CI/CD with Jenkins
Jenkinsfile
example:
pipeline {
agent any
stages {
stage('Install') {
steps {
sh 'pip install -r requirements.txt'
sh 'rfbrowser init'
}
}
stage('Test') {
steps {
sh 'robot tests/'
}
}
stage('Archive') {
steps {
archiveArtifacts artifacts: '**/report.html', fingerprint: true
publishHTML(target: [allowMissing: false, alwaysLinkToLastBuild: true,
keepAll: true, reportDir: '.', reportFiles: 'report.html', reportName: 'Robot Report'])
}
}
}
}
β Requires the HTML Publisher Plugin
10. Custom Libraries with Python
You can build custom Python libraries to extend Robot Framework with your own logic and functionality.
Example custom_library.py
:
class CustomLibrary:
def hello_world(self):
print("Hello from custom Python library!")
Usage in .robot file:
*** Settings ***
Library custom_library.py
*** Test Cases ***
Use Custom Library
Hello World
β Custom libraries are useful for encapsulating business logic, complex workflows, or reusable utilities.
11. Parallel Execution with Pabot
Pabot allows you to run Robot Framework tests in parallel, significantly reducing execution time.
Install it:
pip install robotframework-pabot
Run tests in parallel (e.g., 4 workers):
pabot --processes 4 tests/
β Especially useful for large test suites in CI/CD environments.
12. Allure Report Integration
Allure provides beautiful, detailed reports that can enhance the visibility of your test results.
Install Allure adapter:
pip install robotframework-allure
Run tests with Allure listener:
robot --listener allure_robotframework tests/
allure serve output/allure-results
β Works great with GitHub Actions and Jenkins for interactive test reporting.
13. Data-Driven Testing with Templates
Robot Framework allows you to run multiple variations of a test using templates:
*** Test Cases ***
Login With Valid Credentials
[Template] Login Should Succeed
user1 password1
user2 password2
*** Keywords ***
Login Should Succeed
[Arguments] ${username} ${password}
Open Browser https://example.com chrome
Input Text id=username ${username}
Input Password id=password ${password}
Click Button id=login
Page Should Contain Dashboard
Close Browser
β Clean and scalable way to manage repetitive test logic with different input data.
14. Dockerized Robot Framework
Running Robot Framework in Docker makes it easier to isolate dependencies and integrate in CI/CD.
Dockerfile example:
FROM python:3.11-slim
RUN pip install robotframework \
robotframework-seleniumlibrary \
robotframework-requests \
robotframework-browser
RUN rfbrowser init
WORKDIR /tests
COPY ./tests /tests
CMD ["robot", "."]
β Run tests consistently across environments without installing tools locally.
15. Debugging and Logging Tips
Robot Frameworkβs log.html is a powerful debugging tool. Use built-in keywords to improve visibility:
Log Current value is: ${some_variable}
Capture Page Screenshot
β Helps identify issues faster, especially when combined with --loglevel DEBUG.
16. Security and Secrets Management
Avoid exposing credentials directly in your .robot files.
Best practices:
-
Use environment variables (os.getenv) in custom Python keywords
-
Load secrets from encrypted .env files with python-dotenv
-
Never commit secrets to version control
β Secure your test pipeline when dealing with real APIs or environments.
17. Comparison With Other Tools
Robot Framework vs Cypress
Robot Framework:
β
Keyword-driven, better for non-devs
β
Built-in support for API + UI
π« Slower feedback, not JS-native
Cypress:
β
Developer-friendly, fast browser testing
π« Poor support for multi-browser (no Firefox/IE)
π« API testing is limited
Robot Framework vs Postman/Newman
Robot Framework:
β
Supports UI + API in same suite
β
Reusability with keywords
π« Less beginner-friendly than Postman UI
Postman/Newman:
β
Excellent for exploratory and manual API testing
π« Harder to integrate with UI tests
Robot Framework vs Playwright
Robot Framework:
β
Easier for QA teams
π« Less suited for complex UI workflows
Playwright:
β
Full browser control
β
Fast parallel execution
π« More code-centric (not keyword-driven)
18. Best Practices
β
Keep tests atomic (1 purpose/test)
β
Use resource files for reusable keywords
β
Use page objects or abstraction
β
Structure files by domain (e.g. login.robot, user.robot)
β
Use variables for URLs, credentials
β
Use tags for grouping tests
β
Parallel execution: pabot
β
Lint with robotframework-lint
19. Going Further
Explore powerful libraries:
SeleniumLibrary
β UI/browser automationRequestsLibrary
β HTTP APIsBrowser
(Playwright under the hood)DatabaseLibrary
β SQL validationAppiumLibrary
β Mobile testingSSHLibrary
,Telnet
,FTP
,JSON
,XML
Explore plugins:
- VS Code plugin (Robot Framework Language Server)
- Browser recorder extension
- Jenkins + HTML reporting
Conclusion
Robot Framework provides a powerful, readable, and modular way to test modern apps, whether UI, API, or RPA-based. It bridges the gap between QA and dev teams with its keyword-driven approach, and scales well with CI/CD tools like GitHub Actions and Jenkins.
Further Resources
- robotframework.org β Official Robot Framework website
- Robot Framework User Guide β Comprehensive official documentation
- Robot Framework Browser β Playwright-powered UI automation library
- Robot Framework SeleniumLibrary β Selenium-based browser automation
- Robot Framework RequestsLibrary β HTTP request testing
- Robot Framework IDE Plugin for VS Code β Syntax highlighting, auto-completion, and debugging
- Robot Framework Discourse β Official discussion forum
- Jenkins HTML Publisher Plugin β Test report publishing