Home  Python   Robot frame ...

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:

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

PurposeLibraryInstallation
Web AutomationSeleniumLibrarypip install robotframework-seleniumlibrary
API TestingRequestsLibrarypip install robotframework-requests
DatabaseDatabaseLibrarypip install robotframework-databaselibrary
MobileAppiumLibrarypip install robotframework-appiumlibrary
RPA / Desktoprpaframeworkpip install rpaframework
Playwrightrobotframework-browserrobotframework-browser

🔸 Step 4: (Optional) Install Browser Drivers

For web testing, you’ll need a browser driver (like Selenium):

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

ConceptDescription
Test SuiteCollection of test cases in .robot files
Test CaseIndividual test scenario
KeywordA reusable action or command
VariableA placeholder for values
LibraryExternal module that adds functionality
Resource FileContains 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:

FilePurpose
log.htmlDetailed execution log
report.htmlSummary report
output.xmlMachine-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:

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

FeatureDescription
Framework TypeKeyword-Driven Test Automation
LanguagePython-based (extendable)
SupportsWeb, API, DB, Mobile, RPA
ReportsHTML + XML
ExecutionCLI, Jenkins, Azure, etc.
Best ForAcceptance, E2E, RPA, CI/CD validation
Published on: Oct 19, 2025, 08:45 AM  
 

Comments

Add your comment