- Community Home
- >
- Software
- >
- Software - General
- >
- Mastering Robot Framework: Advanced Concepts for S...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
a week ago
Mastering Robot Framework: Advanced Concepts for Scalable Test Automation
Introduction
In our previous blog Getting Started with Robot Framework: A Beginner's Guide to Test Automation, we explored foundational aspects of Robot Framework—setting up your environment, writing basic web and API tests, using variables, creating reusable keywords, and organizing your test project structure.
This post builds on those fundamentals. If you're comfortable with writing simple test cases and are now looking to scale, integrate with CI/CD pipelines, handle complex data, or work with APIs, SSH, and custom Python libraries—this one’s for you.
Let’s dive into some advanced capabilities that make Robot Framework a powerful ally in enterprise-grade test automation.
Advanced Test Data Handling
Keeping data separate from logic increases test flexibility and maintainability.
CSV Example with CSVLibrary
Install the library:
pip install robotframework-csvlibrary
*** Settings ***
Library CSVLibrary
*** Test Cases ***
Data Driven Test
@{list}= read csv file to list test_data.csv
FOR ${values} IN @{list}
Log Username: ${values[0]}, Password: ${values[1]}
# Use credentials in test steps
END
JSON Handling
*** Settings ***
Library JSONLibrary
*** Test Cases ***
Read JSON File
${data}= Load JSON From File test_data.json
Log ${data}[\"username\"]
JSONLibrary official documentation: JSONLibrary
Handling Dynamic Elements (Selenium)
Dynamic elements can appear with delays due to asynchronous loading. Using explicit waits ensures that tests interact with elements only when they are ready.
Wait Until Element Is Visible xpath=//div[@id='status'] timeout=10s
Element Should Contain xpath=//div[@id='status'] Success
Use Run Keyword And Ignore Error or Run Keyword And Continue On Failure when needed to prevent abrupt test failures.
Error Handling and Reporting
Unexpected failures shouldn't stop test execution. Robot Framework provides ways to handle errors gracefully and generate meaningful reports.
Maximize test reliability with built-in keywords:
- Run Keyword And Continue On Failure
- Run Keyword And Expect Error
- Should Contain
- Fatal Error
- Capture Page Screenshot
*** Test Cases ***
Login Test
[Teardown] Capture Page Screenshot
Run Keyword And Continue On Failure Element Should Be Visible id=login-button
Use different log levels for clarity:
Log Debug info level=DEBUG
Log Warning level=WARN
Screenshots on Failure
To debug failures more effectively, capturing screenshots provides visual evidence of what went wrong.
A must for UI automation:
*** Test Cases ***
Search Test
[Teardown] Capture Page Screenshot
CI/CD Integration (GitLab & GitHub)
Seamless integration of Robot Framework into CI/CD pipelines ensures automated test execution on every code change, improving software quality and delivery speed.
GitLab Example (.gitlab-ci.yml)
robot_tests:
image: python:3.9
before_script:
- python -m venv venv
- source venv/bin/activate # For Linux/macOS
- pip install -r requirements.txt
script:
- robot --outputdir results tests/
artifacts:
paths:
- results/
GitHub Actions Workflow
name: Robot Framework Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Create and Activate Virtual Environment
run: |
python -m venv venv
source venv/bin/activate
- name: Install Dependencies
run: pip install -r requirements.txt
- name: Execute Tests
run: robot --outputdir results tests/
- name: Upload Test Results
uses: actions/upload-artifact@v3
with:
name: robot-reports
path: results/
Using Robot Framework with Jenkins
Install the Robot Framework Plugin in Jenkins.
Add a build step:
robot --outputdir reports tests/
Use the Post-build Actions to publish test results.
Learn more about Jenkins integration: Robot Framework Jenkins Plugin
Advanced Features in Robot Framework
Robot Framework allows you to extend its capabilities using custom Python libraries, enabling more complex test logic and interactions.
Create your own Python functions and use them as Robot keywords.
# Example: my_custom_library.py
class MyCustomLibrary:
def custom_keyword(self, message):
print(f"Custom Keyword Executed: {message}")
- Using the library in Robot Framework:
*** Settings ***
Library my_custom_library.py
*** Test Cases ***
Run Custom Keyword
Custom Keyword Hello, Robot Framework!
Parallel Test Execution with Pabot
Pabot allows you to execute your Robot Framework tests in parallel, reducing the overall execution time significantly.
pip install robotframework-pabot
pabot --processes 4 --outputdir results tests/
More on Pabot: Pabot Documentation
Robot Framework provides powerful support for API testing, especially when working with RESTful services and token-based authentication.
Handling token authentication and making API calls:
*** Settings ***
Library RequestsLibrary
*** Variables ***
${BASE_URL} https://api.example.com
${AUTH_PAYLOAD} {"username": "test", "password": "pass"}
*** Test Cases ***
Get Auth Token
Create Session auth ${BASE_URL}
${response}= POST On Session auth /auth json=${AUTH_PAYLOAD}
${token}= Set Variable ${response.json()}[token]
Set Global Variable ${token}
GET Request Example
${response}= GET On Session auth /users headers=Authorization=Bearer ${token}
Log ${response.json()}
Restful Example: Robot Framework Requests Library Example
Robot Framework allows seamless interaction with remote systems over SSH, enabling you to automate tasks like server setup, configuration, or execution of commands.
pip install robotframework-sshlibrary
- Test file using SSH Library
*** Settings ***
Library SSHLibrary
*** Variables ***
${HOST} 192.168.1.100
${USER} testuser
${PASSWORD} testpassword
${COMMAND} uptime
*** Test Cases ***
Connect to Server and Run Command
Open Connection ${HOST}
Login ${USER} ${PASSWORD}
${output}= Execute Command {COMMAND}
Log ${output}
Close Connection
More on SSH Library: SSHLibrary Docs, SSHLibrary GitHub
Robot Framework can easily handle Excel files using the RPA.Excel.Files library. It allows reading data as tables, looping through rows, and using TRY/EXCEPT for error handling. This makes data-driven testing with spreadsheets both simple and reliable.
Install required library:
pip install rpaframework
- Test file handling excel data:
*** Settings ***
Library RPA.Excel.Files
*** Test Cases ***
Read Excel
TRY
Open Workbook data.xlsx
${rows}= Read Worksheet As Table header=True
FOR ${row} IN @{rows}
Log ${row}[\"username\"]
END
Close Workbook
EXCEPT AS ${ERROR}
Log To Console Error: ${ERROR}
END
Conclusion
Robot Framework is far more than just a beginner-friendly automation tool. With powerful extensibility, data integration, parallel execution, and seamless CI/CD compatibility, it’s an ideal choice for teams aiming to scale test automation quickly and reliably.
While this blog explores several advanced concepts—from custom libraries and data-driven testing to CI/CD integration and SSH command execution—Robot Framework offers even more flexibility through its ecosystem of libraries and plugins. Depending on your project needs, you can extend it further for performance testing, database validations, UI automation enhancements, and integrations with other tools.
Think of this blog as a strong foundation for exploring what's possible with Robot Framework. As your automation grows, so can the capabilities of the framework.
Are you using advanced features of Robot Framework in your projects? Share your experiences and tips in the comments!
References
Robot Framework Sample Example
Getting Started with Robot Framework: A Beginner's Guide to Test Automation
Amit Pisal
Hewlett Packard Enterprise (PS-GCC)
I work at HPE
HPE Support Center offers support for your HPE services and products when and how you need it. Get started with HPE Support Center today.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
