Post thumbnail
SOFTWARE AUTOMATION & TESTING

Understanding the Basics of Robot Framework

By Suman Gangopadhyay

Have you ever wondered how businesses ensure their applications run flawlessly across multiple platforms and devices? It is because of Robot Framework, a powerful, open-source automation framework that simplifies testing for even non-programmers.

With its keyword-driven approach and seamless integration with tools like Selenium, Appium, and Jenkins, Robot Framework has become a go-to solution for efficient, scalable, and maintainable test automation.

Let’s explore the core features, architecture, and real-world applications that make this tool a game-changer in the world of software testing.

Table of contents


  1. What is Robot Framework?
  2. Key Features of Robot Framework
  3. How Robot Framework Works?
  4. Benefits of Using Robot Framework
  5. Usage of Robot Framework
  6. Robot Framework Architecture
    • Settings
    • Variables
    • Test Cases
    • Keywords
    • Settings Section
    • Variables Section
    • Test Cases Section
    • Keywords Section
    • Execution Command
    • Overall Flow of the Test Case:
  7. Conclusion

What is Robot Framework?

Robot Framework is a versatile open-source automation framework that has gained significant popularity in recent years. Its modular and extensible architecture, coupled with its ease of use, makes it an ideal choice for automating a wide range of tasks.

Robot Framework is a keyword-driven automation framework that is designed to be easy to use even for non-programmers. It uses a simple English-like syntax to define test cases and keywords, making it accessible to a broad range of users.

The framework’s modular architecture allows for seamless integration with various tools and technologies, making it highly adaptable to different automation needs.

Key Features of Robot Framework

  • Keyword-Driven Automation Testing : Robot Framework employs a keyword-driven approach where test cases are defined using reusable keywords. This promotes code reusability and maintainability.
  • Data-Driven Testing : Robot Framework supports data-driven testing enabling users to execute the same test case with different data sets right from an Excel file, CSV file and Databases. This is particularly useful for testing applications with varying input values.
  • Reporting : The framework generates detailed test reports and logs providing valuable insights into test execution. 
  • Integration with Other Tools: Robot Framework can be integrated with various tools and technologies, such as Selenium for web testing, Appium for mobile app testing, and Jenkins for continuous integration and of course with Microsoft PlayWright automation testing framework. Now only that we can also use the Behavior Driven Development (BDD) Gherkin which allows us to test complex tasks.

How Robot Framework Works?

  1. Test Data: Test cases and keywords are defined in test data files using a simple syntax. These files can be written in plain text or HTML format.
  2. Keyword Execution: When a test case is executed, the framework resolves the keywords used in the test case and executes them. Keywords can be built-in or custom.
  3. Variable Substitution: Robot Framework supports variable substitution, allowing users to parameterize test data and make tests more dynamic.
  4. Reporting: The framework generates test reports in various formats, including HTML, XML, and JSON. These reports provide detailed information about test execution, including pass/fail status, execution time, and error messages.

Benefits of Using Robot Framework

  • Increased Efficiency: Robot Framework can significantly improve the efficiency of testing processes by automating repetitive tasks. This frees up time for testers to focus on more complex activities.
  • Improved Quality: By automating testing, Robot Framework can help to improve the overall quality of software applications. It can help to identify defects early in the development process, reducing the cost of fixing them later.
  • Reduced Costs: Automation can help to reduce the costs associated with testing. By automating repetitive tasks, organizations can save money on labor costs and reduce the risk of human errors.
  • Improved Collaboration: Robot Framework can facilitate collaboration between testers, developers, and other stakeholders. By using a common language and framework, teams can work together more effectively.

Usage of Robot Framework

Robot Framework is used in a wide range of applications including:

  • Web Application Testing: Robot Framework can be used to automate testing of web applications, including functional testing, regression testing, and performance testing.
  • API Testing: The framework can be used to test APIs, ensuring that they are functioning correctly and returning the expected results.
  • Mobile App Testing: Robot Framework can be used to automate testing of mobile apps, including functional testing, performance testing, and compatibility testing with the help of Appium mobile testing framework.
  • Database Testing: The framework can be used to test databases like MySQL, Oracle, MariaDB, PostgreSQL ensuring that data is being stored, retrieved, and updated correctly using CRUD methodologies.
MDN

Robot Framework Architecture

The following image given below shows the architecture design and setup of High-Level Robot framework :- 

Robot Framework Architecture

The Robot Framework architecture is a modular and extensible platform for automating tasks. It consists of several key components:

1. Robot Framework Core:

  • Parser: Reads test cases and keywords from various formats (e.g., HTML, TXT, ReST).
  • Variable Resolver: Handles variables and data-driven testing.
  • Keyword Executor: Executes keywords, which can be built-in or custom.
  • Test Case Executor: Executes test cases, coordinating the execution of keywords.
  • Result Writer: Generates test reports in various formats (e.g., HTML, XML).

2. Libraries:

  • Built-in Libraries: Provide basic functionalities like variables, loops, conditionals, and file operations.
  • External Libraries: Offer specific functionalities for interacting with different systems or technologies (e.g., Selenium for web testing, SSH for remote execution).

3. Test Data:

  • Test cases and keywords are defined in test data files using a simple syntax.
  • Variables can be used to parameterize test data.

4. Execution:

  • The Robot Framework interpreter reads the test data files and executes the test cases.
  • Keywords are executed, and results are recorded.

5. Reporting:

  • The framework generates test reports in various formats, providing detailed information about test execution, including pass/fail status, execution time, and error messages.

Installation of Robot Framework

To install Robot framework into your system you need Python 3.5+ with PIP command accessible from the command line or terminal. The command to install Robot framework is as follows :- 

pip install robotframework

pip install robotframework

pip install robotframework-seleniumlibrary

pip install robotframework-seleniumlibrary

Kindly note that with the command pip install robotframework-seleniumlibrary you can install the Robot Framework as well as the SeleniumLibrary which is very essential for automation of web applications. So, even if you have used the pip install robotframework you need to use pip install robotframework-seleniumlibrary but if you have ran the command pip install robotframework-seleniumlibrary it is no longer necessary and needed to use the pip install robotframework.

Understanding the Robot Script  File

Now, since we introduced ourselves with Robot framework and learnt about its high-level architecture now it is time to understand the basic script of Robot framework.

But, before writing the main test-script file it will be imperative to understand the basics of a Robot test-script file first. Generally, a Robot test-file looks like this 

Robot Script  File

Let us now understand what are the things in details :- 

Settings

The Settings section in a Robot Framework test suite defines the framework’s configuration. It includes:

  • Documentation: Provides a brief description of the test suite.
  • Suite Setup: A keyword that runs before the entire suite.
  • Suite Teardown: A keyword that runs after the entire suite.
  • Test Setup: A keyword that runs before each test case.
  • Test Teardown: A keyword that runs after each test case.
  • Default Tags: Tags that are applied to all test cases unless overridden.

Variables

Variables in Robot Framework are used to store data that can be reused throughout the test suite. They can be:

  • Global Variables: Defined at the suite level and accessible to all test cases.
  • Scalar Variables: Store a single value.
  • List Variables: Store a list of values.
  • Dictionary Variables: Store key-value pairs.

Test Cases

Test cases are the individual units of testing in Robot Framework. They consist of a series of keywords that describe the steps to be performed during the test. Each test case has:

  • Name: A descriptive name for the test case.
  • Documentation: A brief description of the test case.
  • Tags: Keywords that categorize the test case for reporting and selection purposes.
  • Keywords: The actions to be performed during the test.

Keywords

Keywords are the building blocks of Robot Framework. They represent reusable actions or operations that can be called from within test cases. Keywords can be:

  • Built-in Keywords: Provided by the framework itself for common tasks like opening URLs, clicking elements, and verifying text.
  • User-defined Keywords: Created by the user to encapsulate custom logic or frequently used sequences of actions.

First Robot Script File

We have created a Robot test-case file by the name “TestGuvi.robot” and a basic test-case has been written inside it as below. The description of the file is as follows :- 

*** Settings ***

Documentation    Automation Testing of Guvi Homepage

Library    SeleniumLibrary

# Run the Script

# robot -d Results Tests\GuviHomePage.robot

*** Variables ***

${url}  https://www.guvi.in

*** Test Cases ***

Testing the Homepage of GUVI

   [Documentation]    Open the homepage of GUVI using Chrome Browser

   [Tags]    GUVI001   FirstTest   GUVIHomePage

   set selenium timeout    5s

   log    Log the Robot Automation Testing

   open browser    ${url}     chrome

   sleep    2s

   close all browsers

***Keywords ***

This script is a test automation script for the GUVI homepage written using the Robot Framework, which integrates Selenium for browser automation. Below is a detailed explanation of the various sections and commands in the script:

1. Settings Section

The *** Settings *** section defines the overall configuration of the test, including libraries, resources, and metadata required for execution.

  • Documentation Automation Testing of Guvi Homepage: This line adds a description to the test suite, explaining that it is intended for automation testing of GUVI’s homepage.
  • Library SeleniumLibrary: This imports the Selenium Library into the Robot Framework, allowing the script to perform browser-based automation tasks.

2. Variables Section

The *** Variables *** section declares global variables that can be used throughout the script.

  • ${url} https://www.guvi.in: This variable stores the URL of the GUVI homepage. Using variables makes the script more maintainable, as any changes to the URL only need to be updated here.

3. Test Cases Section

The *** Test Cases *** section defines the actual test scenarios. In this case, there is one test case:

Test Case: Testing the Homepage of GUVI

  • [Documentation]: Provides a brief description of the test case. It mentions that the test will open the GUVI homepage using the Chrome browser.
  • [Tags]: Tags like GUVI001, FirstTest, and GUVIHomePage are applied. These are useful for identifying, organizing, and grouping tests when running a large number of test cases.

Steps within the Test Case:

  1. set selenium timeout 5s: This sets the Selenium timeout to 5 seconds. This means that Selenium will wait up to 5 seconds for elements to be present before throwing a timeout error.
  2. log Log the Robot Automation Testing: This logs a custom message “Log the Robot Automation Testing” to the console or report, which is useful for debugging and reporting purposes.
  3. open browser ${url} chrome: This command opens a browser window (Chrome) and navigates to the URL stored in the ${url} variable, which is the GUVI homepage.
  4. sleep 2s: This pauses the execution for 2 seconds, allowing the page to load completely before proceeding with the next step. Using sleep is sometimes helpful when pages take longer to load.
  5. close all browsers: This closes all open browser instances at the end of the test, ensuring that no browser windows are left running after the test finishes.

4. Keywords Section

  • *** Keywords ***: This section is empty in the script. Typically, it is used to define custom keywords, which are reusable blocks of code that can be called across different test cases. In this case, no custom keywords are defined.

Execution Command

The script provides a comment line showing how to run the test from the command line:
# Run the Script

# robot -d Results Tests\GuviHomePage.robot

  • robot is the command to run Robot Framework tests.
  • -d Results specifies that the results should be saved in the Results folder.
  • Tests\GuviHomePage.robot is the path to the test file.

Overall Flow of the Test Case:

  1. The script starts by setting a 5-second timeout for Selenium actions.
  2. It logs a message for debugging.
  3. It opens the GUVI homepage in Chrome.
  4. The script waits for 2 seconds to ensure the page loads completely.
  5. Finally, it closes all browser windows.

The Result Files

When you run a Robot Test-Case file three Test Report files gets generated they are as follows :- 

  1. log.html
  2. output.xml
  3. report.html

Report.html

The Result Files

The report.html file in Robot Framework is a comprehensive HTML report that provides a detailed overview of the test execution results. It serves as a valuable resource for analyzing the success and failure of test cases, identifying potential issues, and tracking the overall progress of the testing process.

Key Features of the report.html File:

  • Test Case Summary: A tabular representation of all test cases, including their status (passed, failed, skipped), name, duration, and any error messages.
  • Test Suite Summary: A summary of each test suite, providing information about the number of test cases, passed, failed, skipped, and the overall test suite status.
  • Statistics: A statistical analysis of the test execution, including the total number of test cases, test suites, passed, failed, skipped, and the overall pass rate.
  • Keyword Statistics: A breakdown of keyword execution statistics, showing the number of times each keyword was executed, passed, failed, and skipped.
  • Log Output: Detailed log information for each test case, including the execution steps, variable values, and any error messages.
  • Screenshots: If configured, screenshots captured during test execution are included in the report, providing visual evidence of failures or unexpected behavior.

Benefits of Using the report.html File:

  • Comprehensive Analysis: The report provides a detailed view of test execution results, making it easier to identify and address issues.
  • Efficient Debugging: The log output and screenshots can help pinpoint the root cause of test failures.
  • Progress Tracking: The report can be used to monitor the progress of the testing process and identify areas that require attention.

Output.xml

Output.xml

The output.xml file in Robot Framework is a comprehensive report that captures detailed information about the test execution. It provides a structured representation of the test cases, their status (pass, fail, or skipped), execution time, and any error messages or captured screenshots.

Key Elements of the output.xml File:

  • Test Suite: Contains information about the overall test suite, including its name, start time, end time, and total test cases.
  • Test Case: Each test case within the suite is represented, with details such as its name, status, execution time, criticality (whether it’s critical to pass), and any associated tags.
  • Keyword: The keywords executed within each test case are listed, along with their arguments, return values, and execution time.
  • Message: Any messages or errors encountered during test execution are recorded here, including their level (INFO, DEBUG, WARN, ERROR, or CRITICAL).

log.html

log.html
Third log

The log.html file in Robot Framework is a comprehensive report that provides a detailed overview of the test execution. It serves as a valuable resource for analyzing test results, identifying failures, and understanding the overall health of the test suite.

Key features and content of the log.html file:

  • Test Case Summary: A list of all test cases executed, along with their status (passed, failed, skipped, etc.) and execution time.
  • Keyword Execution Details: A breakdown of each keyword used in the test cases, including its parameters, return values, and execution time.
  • Failure Details: Detailed information about failed test cases, including error messages, screenshots (if captured), and the specific keyword or step that caused the failure.
  • Suite Statistics: Summary information about the entire test suite, such as the total number of test cases, passed/failed/skipped counts, and overall execution time.
  • Tags: Information about the tags associated with test cases, which can be used for filtering and grouping tests.
  • Variables: A list of variables used during the test execution, along with their values.
  • Configuration: Details about the Robot Framework environment, such as the Python version, libraries used, and command-line arguments.

If you want to learn more about Selenium Automation, consider enrolling for GUVI’s Selenium Automation Testing Course that help in mastering in-demand skills like Selenium, Python, Jenkins, Jmeter, API Testing, and more.

MDN

Conclusion

In conclusion, Robot Framework’s combination of readability, extensibility, flexibility, and a strong community makes it a compelling choice for test automation. Its ability to handle diverse testing scenarios and its user-friendly approach contribute to its growing popularity among software development teams worldwide.

Career transition

Did you enjoy this article?

Schedule 1:1 free counselling

Similar Articles

Loading...
Share logo Copy link
Power Packed Webinars
Free Webinar Icon
Power Packed Webinars
Subscribe now for FREE! 🔔
close
Webinar ad
Table of contents Table of contents
Table of contents Articles
Close button

  1. What is Robot Framework?
  2. Key Features of Robot Framework
  3. How Robot Framework Works?
  4. Benefits of Using Robot Framework
  5. Usage of Robot Framework
  6. Robot Framework Architecture
    • Settings
    • Variables
    • Test Cases
    • Keywords
    • Settings Section
    • Variables Section
    • Test Cases Section
    • Keywords Section
    • Execution Command
    • Overall Flow of the Test Case:
  7. Conclusion