Robot Framework in Python
Here’s a complete, detailed guide to Robot Framework — now including installation, environment setup, and test execution commands.
🤖 Robot Framework — Complete Overview
🧩 1️⃣ What is Robot Framework
Robot Framework (RF) is an open-source, keyword-driven test automation and RPA framework that enables both technical and non-technical testers to:
- Write human-readable test cases
- Automate Web, API, Database, Mobile, and Desktop testing
- Run in CI/CD pipelines (Jenkins, Azure DevOps, etc.)
It is language-agnostic but most commonly extended in Python.
⚙️ 2️⃣ Installation Steps
Robot Framework runs on Python, so let’s start there.
🔸 Step 1: Install Python
Download from https://www.python.org/downloads Make sure to check “Add Python to PATH” during installation.
Verify installation:
python --version
pip --version
🔸 Step 2: Install Robot Framework Core
pip install robotframework
Verify installation:
robot --version
You should see something like:
Robot Framework 7.0 (Python 3.12)
🔸 Step 3: (Optional) Install Additional Libraries
| Purpose | Library | Installation |
|---|---|---|
| Web Automation | SeleniumLibrary | pip install robotframework-seleniumlibrary |
| API Testing | RequestsLibrary | pip install robotframework-requests |
| Database | DatabaseLibrary | pip install robotframework-databaselibrary |
| Mobile | AppiumLibrary | pip install robotframework-appiumlibrary |
| RPA / Desktop | rpaframework | pip install rpaframework |
| Playwright | robotframework-browser | robotframework-browser |
🔸 Step 4: (Optional) Install Browser Drivers
For web testing, you’ll need a browser driver (like Selenium):
- Chrome → Install ChromeDriver
- Edge/Firefox/Safari → Install corresponding driver
Make sure it’s added to your system PATH.
🧱 3️⃣ Folder Structure
A clean project setup looks like this:
robot-tests/
│
├── tests/
│ ├── login_tests.robot
│ ├── api_tests.robot
│
├── resources/
│ ├── keywords.robot
│ ├── variables.robot
│
├── libraries/
│ └── custom_keywords.py
│
├── results/
│ ├── log.html
│ ├── report.html
│
└── requirements.txt
🧠 4️⃣ Core Concepts Recap
| Concept | Description |
|---|---|
| Test Suite | Collection of test cases in .robot files |
| Test Case | Individual test scenario |
| Keyword | A reusable action or command |
| Variable | A placeholder for values |
| Library | External module that adds functionality |
| Resource File | Contains shared keywords or variables |
🧪 5️⃣ Example Test Case — Selenium
tests/example_web_test.robot
*** Settings ***
Library SeleniumLibrary
*** Variables ***
${URL} https://example.com
${BROWSER} Chrome
*** Test Cases ***
Verify Example Domain Title
Open Browser ${URL} ${BROWSER}
Title Should Be Example Domain
[Teardown] Close Browser
🧪 6️⃣ Example Test Case — API
tests/api_test.robot
*** Settings ***
Library RequestsLibrary
*** Variables ***
${BASE_URL} https://jsonplaceholder.typicode.com
*** Test Cases ***
Verify Get User Details
Create Session jsonAPI ${BASE_URL}
${response}= Get Request jsonAPI /users/1
Should Be Equal As Integers ${response.status_code} 200
Log To Console ${response.json()}
🚀 7️⃣ Running Tests
Run All Tests
robot tests/
Run Specific File
robot tests/example_web_test.robot
Run Tests by Tag
robot -i smoke tests/
Specify Output Directory
robot --outputdir results tests/
📊 8️⃣ Test Reports
After running, Robot Framework automatically creates:
| File | Purpose |
|---|---|
log.html | Detailed execution log |
report.html | Summary report |
output.xml | Machine-readable report (for CI/CD) |
Open them in a browser — they include test results, screenshots (if configured), and timing info.
🧩 9️⃣ Extending Robot Framework
You can define your own custom keywords using Python or Java.
Example: Python Custom Library
libraries/custom_keywords.py
from robot.api.deco import keyword
@keyword("Add Two Numbers")
def add_two_numbers(a, b):
return int(a) + int(b)
Then use it in Robot:
*** Settings ***
Library ../libraries/custom_keywords.py
*** Test Cases ***
Add Numbers
${result}= Add Two Numbers 3 7
Should Be Equal As Integers ${result} 10
🔁 🔟 CI/CD Integration
Robot Framework easily integrates with:
- Jenkins (via
Robot Plugin) - Azure DevOps Pipelines
- GitHub Actions
- GitLab CI
- Docker (containerized test runs)
Example Jenkins command:
robot --outputdir reports tests/
🧮 11️⃣ Advantages
✅ Simple, readable syntax ✅ Modular — reusable keywords ✅ Supports Web, API, DB, and Mobile testing ✅ Easy CI/CD integration ✅ Great reports out of the box ✅ Can use Python or Java libraries ✅ Active community & rich plugin ecosystem
⚠️ 12️⃣ Limitations
❌ Not suited for low-level or very complex logic ❌ Can be verbose for conditions/loops ❌ Debugging requires looking into reports ❌ Slower than raw code frameworks
🧠 13️⃣ Summary Table
| Feature | Description |
|---|---|
| Framework Type | Keyword-Driven Test Automation |
| Language | Python-based (extendable) |
| Supports | Web, API, DB, Mobile, RPA |
| Reports | HTML + XML |
| Execution | CLI, Jenkins, Azure, etc. |
| Best For | Acceptance, E2E, RPA, CI/CD validation |