- Community Home
- >
- Software
- >
- Software - General
- >
- Getting Started with Robot Framework: A Beginner'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
Monday
Monday
Getting Started with Robot Framework: A Beginner's Guide to Test Automation
Introduction to Test Automation Frameworks
Automation testing frameworks are essential for developing robust and scalable automated test suites. These frameworks provide a structured way to write, organize, and maintain test cases. There are several automation testing frameworks available today, each suited for different types of testing and team needs.
Popular Automation Frameworks in the Market
Selenium – A widely-used tool for browser-based automation, supporting multiple programming languages and offering deep control over UI elements.
PyTest – A Python-based framework known for its simplicity and flexibility. Ideal for unit and API testing, with strong plugin support and minimal boilerplate.
TestNG – A Java testing framework often used with Selenium. It supports annotations, data-driven testing, and parallel execution.
Cypress – A modern JavaScript framework for fast, reliable end-to-end testing directly in the browser. Great for front-end developers.
Robot Framework – A keyword-driven, easy-to-read framework that supports web, API, and other testing types through extensible libraries.
Why Choose Robot Framework?
Robot Framework is an open-source Test Automation Framework that supports multiple testing types, including API Testing, Web Application Testing, and Database Testing. Key features include:
Keyword-driven: Uses reusable, human-readable keywords, making it accessible to non-programmers.
Data-driven: Simplifies creating tests with data-driven approaches.
Extensibility: Integrates seamlessly with Python, Java, and other languages to extend functionality via custom libraries.
Rich Reporting: Generates detailed HTML and XML reports out-of-the-box.
Multi-domain Testing: Supports RESTful API testing, SSH Library for system access and command execution, and more. (Selenium, Requests, SSH, etc.)
Integration Friendly: Works with Selenium, Appium, Requests, and other libraries.
This blog focuses on fundamentals of Robot Framework and is ideal for automation testers who want to begin using it in their projects.
Learn more in the official docs: Robot Framework
Setting Up Robot Framework
To start using Robot Framework, make sure you have Python installed on your system (Python 3.6 or newer is recommended). Once that's set up, you can install Robot Framework using pip, the Python package manager:
Set up your virtual environment:
```bash
python -m venv robot_env
Activate the environment:
On Linux/macOS:
source robot_env/bin/activate
On Windows:
robot_env\Scripts\activate
To get started
Following command will install the core Robot Framework, which provides the test execution engine and basic functionality. Once installed, you can begin writing test cases using plain text syntax in .robot files. For additional capabilities like web automation or API testing, you can install external libraries such as SeleniumLibrary, RequestsLibrary, and others.
pip install robotframework
For web automation, install SeleniumLibrary:
To perform web automation using Robot Framework, you need to install SeleniumLibrary, which provides keywords for interacting with web browsers.
pip install robotframework-seleniumlibrary
For REST API testing, install RequestsLibrary:
To perform RESTful API testing using Robot Framework, you need to install RequestsLibrary, which provides easy-to-use keywords for sending HTTP requests and validating responses.
pip install robotframework-requests
Writing Your First Test
Selenium Example
*** Settings ***
Library SeleniumLibrary
*** Test Cases ***
Open Browser and Search
Open Browser https://www.google.com chrome
Input Text name=q Robot Framework
Press Keys name=q ENTER
Close Browser
SeleniumLibrary official documentation: SeleniumLibrary Docs
REST API Example
*** Settings ***
Library RequestsLibrary
*** Test Cases ***
Simple GET Request
${response}= GET https://jsonplaceholder.typicode.com/posts/1
Should Be Equal As Numbers ${response.status_code} 200
Log ${response.json()}
RequestsLibrary official documentation: RequestsLibrary Docs
Best Practices for Writing Clean and Maintainable Tests
Use Variables for Maintainability:
Using variables in Robot Framework improves maintainability and reduces redundancy. You can define:
- Local variables within a test case (specific to that test).
- Common variables in a separate variables file under the Resources section for reusability across multiple tests.
*** Variables ***
${URL} https://www.example.com
Create Reusable Keywords (Resource Files):
Robot Framework allows you to create reusable keywords in resource files, making test cases more modular and maintainable. You can store frequently used steps as custom keywords and import them into multiple test cases.
# Example: common.resource
*** Variables ***
${URL} https://www.example.com
*** Keywords ***
Open Example Page
Open Browser ${URL} chrome
- Test file using the resource:
*** Settings ***
Resource common.resource
Library SeleniumLibrary
*** Test Cases ***
Example Test
Open Example Page
# ... other steps ...
Implement Logging for Debugging:
Logging is essential in test automation to track execution progress and diagnose issues. Robot Framework provides built-in logging mechanisms to print messages to the console and save them in logs for debugging.
Log To Console Execution Started # Prints message in the console
Log Test execution in progress # Logs message in the report
Log This is a debug message level=DEBUG # Logs with DEBUG level
Log This is a warning level=WARN # Logs with WARNING level
Use Tags to Organize and Filter Tests:
Tags help in categorizing and selectively running test cases based on priority, functionality, or type. They make test execution more flexible and manageable, especially in large automation projects.
*** Test Cases ***
Login Test
[Tags] smoke login
# Test steps for login functionality
API Test
[Tags] api
# Test steps for API validation
Regression Test
[Tags] regression critical api
# Steps for regression testing
- Run specific tagged tests via command line:
robot --include smoke tests/
robot --exclude regression tests/
robot --include api --include login tests/
robot --include api --exclude critical tests/
Add Documentation
Robot Framework allows you to add documentation directly within your test cases, test suites, and user-defined keywords. This improves test readability, understanding, and maintainability—especially in large projects or teams where tests are shared.
*** Settings ***
Documentation Test suite for validating user login scenarios.
*** Test Cases ***
Login Test
[Documentation] This test case verifies the login functionality.
*** Keywords ***
Enter Login Credentials
[Arguments] ${username} ${password}
[Documentation] Enters the provided username and password into the login form.
Test Suite Example: Putting Best Practices into Action
This example demonstrates how to integrate key Robot Framework best practices—variables, custom keywords, logging, tags, and documentation—to create a well-structured and maintainable web login test.
# Example: variables.robot
*** Variables ***
${URL} https://example.com/login
${BROWSER} chrome
${USERNAME} testuser
${PASSWORD} secret123
${LOGIN_TITLE} Dashboard
# Example: keywords.robot
*** Settings ***
Library SeleniumLibrary
Resource variables.robot
*** Keywords ***
Open Browser To Login Page
[Documentation] Opens browser and navigates to the login page
Open Browser ${URL} ${BROWSER}
Maximize Browser Window
Set Selenium Speed 0.5s
Input Credentials And Login
[Arguments] ${username} ${password}
[Documentation] Inputs given credentials and clicks login
Input Text id=username ${username}
Input Text id=password ${password}
Click Button id=loginBtn
Should See Dashboard
[Documentation] Verifies that the user lands on the dashboard
Title Should Be ${LOGIN_TITLE}\
# Example: login_test.robot
*** Settings ***
Documentation Test suite to verify login functionality.
Library SeleniumLibrary
Resource ../resources/variables.robot
Resource ../resources/keywords.robot
Suite Setup Open Browser To Login Page
Suite Teardown Close All Browsers
*** Test Cases ***
Valid Login With Correct Credentials
[Documentation] This test verifies that a user can log in with valid credentials.
[Tags] smoke login
Input Credentials And Login ${USERNAME} ${PASSWORD}
Should See Dashboard
Log Login successful with user: ${USERNAME}
Recommended Project Structure
A well-organized directory structure is essential for maintainable and scalable test automation. It helps separate concerns, reuse components, and manage test data efficiently.
robot-tests/
├── tests/ # Main directory for test cases
│ ├── web/ # Web UI-related tests
│ └── api/ # API-related tests
├── resources/ # Reusable keywords and variables
│ ├── keywords.resource # Custom keywords
│ └── variables.resource # Common variables
├── test_data/ # External test data (CSV, JSON, Excel)
├── results/ # Output directory for logs, reports, and screenshots
├── libs/ # Python custom libraries if any
├── config/ # Environment-specific configurations (e.g., dev, test)
├── requirements.txt # Python dependencies
└── README.md # Project overview and usage instructions
Comparing Robot Framework with Other Test Automation Frameworks
automation_frameworks_comparison
Conclusion
Robot Framework is an excellent choice for teams starting out with test automation due to its readable syntax, powerful libraries, and ease of integration. Mastering the fundamentals like project structure, best practices, and basic test writing will set a strong foundation for scaling your test automation efforts.
In the next blog, we will explore advanced features such as custom libraries, parallel execution, CI/CD integration, and more!
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]
