Robot Framework in Automation Testing
Introduction
Robot Framework is an open-source, keyword-driven test automation framework that is widely used for acceptance testing, acceptance test-driven development (ATDD), and Robotic Process Automation (RPA). It is built on top of Python and provides an easy-to-use syntax for writing test cases.
It supports various test automation libraries such as Selenium for web automation, Appium for mobile automation, and RESTinstance for API testing. Robot Framework uses a tabular test data syntax, making it simple to understand and use.
Key Features
-
Keyword-driven approach: Uses predefined and user-defined keywords.
-
Easy integration: Can integrate with Selenium, Appium, REST APIs, etc.
-
Extensible: Supports external libraries and custom Python scripts.
-
Supports Parallel Execution: Can execute tests concurrently.
-
Detailed Reports & Logs: Generates structured test reports.
-
Platform Independent: Runs on Windows, Linux, and macOS.
Installation of Robot Framework
To install Robot Framework, use the following command:
pip install robotframework
For web automation using Selenium, install the Selenium library:
pip install robotframework-seleniumlibrary
Writing a Simple Test Case
A test case in Robot Framework consists of keywords that define test steps. The syntax is similar to natural language, making it easy to read.
Example: Automating a Login Page with Selenium
1. Install Required Libraries
Ensure you have the following installed:
pip install robotframework-seleniumlibrary
2. Create a Test Suite File (login_test.robot
)
*** Settings ***
Library SeleniumLibrary
*** Variables ***
${BROWSER} Chrome
${URL} https://example.com/login
${USERNAME} testuser
${PASSWORD} testpass
*** Test Cases ***
Valid Login Test
Open Browser ${URL} ${BROWSER}
Input Text id=username ${USERNAME}
Input Text id=password ${PASSWORD}
Click Button id=loginButton
Wait Until Page Contains Welcome 5s
Capture Page Screenshot
Close Browser
3. Running the Test
Execute the test using the following command:
robot login_test.robot
4. Viewing the Reports
After execution, Robot Framework generates:
-
log.html
: Detailed execution logs. -
report.html
: Summary of test results.
To view the reports, open report.html
in a web browser.
Advanced Concepts
1. Creating Custom Keywords
You can define reusable keywords in a Resource
file.
Example: keywords.resource
*** Settings ***
Library SeleniumLibrary
*** Keywords ***
Login To Application
[Arguments] ${username} ${password}
Input Text id=username ${username}
Input Text id=password ${password}
Click Button id=loginButton
Using the Custom Keyword in a Test Case
*** Settings ***
Resource keywords.resource
*** Test Cases ***
Valid Login Test
Open Browser https://example.com/login Chrome
Login To Application testuser testpass
Wait Until Page Contains Welcome 5s
Close Browser
Integrating Robot Framework with CI/CD
Robot Framework can be integrated into Jenkins, GitHub Actions, or other CI/CD tools for automated test execution.
Example: Running Tests in Jenkins
-
Install Robot Framework in the Jenkins environment.
-
Use a Jenkins pipeline script to execute tests:
pipeline {
agent any
stages {
stage('Run Tests') {
steps {
sh 'robot -d results tests/'
}
}
}
}
-
After execution, configure Jenkins to publish
report.html
as a test result.
Conclusion
Robot Framework is a powerful and flexible automation testing tool with a simple syntax. It is suitable for web testing, mobile testing, API testing, and more. With its keyword-driven approach and easy integration with other tools, Robot Framework is widely used in test automation.