Robot_Framework

Robot Framework

Robot Framework is an open source test automation framework for acceptance testing and acceptance test-driven development.

It follows different test case styles βˆ’ keyword-driven, behaviour-driven and data-driven for writing test cases.

Robot Framework provides support for external libraries, tools which are open source and can be used for automation.

Test cases are written .robot or .txt files using keyword style in a tabular format.

Robot framework works fine on all the Operating Systems available.

The framework is built on Python and runs on Jython (JVM) and IronPython (.NET).

Robot Framework Sections

The four sections of basic Robot test scripts are setting, variables, keywords, and test cases.

1. Settings

The settings section contains the import statements for the external libraries, resources, and the setup and teardown commands.

*** Settings ***
Library           SeleniumLibrary
Suite Setup       Open Browser    ${URL}    ${BROWSER}
Suite Teardown    Close All Browsers
Resource		  CommonKeywords.robot

The Settings section includes the SeleniumLibrary and sets up the Suite Setup and Teardown, as well as importing an external resource file.

Libraries: Robot framework has support for a lot of external libraries like SeleniumLibrary, Database Library, FTP Library and http library. Robot framework also has its own built-in libraries for strings, date, numbers etc.

Resources: Robot framework also allows the import of robot files with keywords externally to be used with test cases.

2. Variables

The variables section contains keyword arguments, global, and local values. Variables make it easy to change the test data in one location.

Robot framework supports variables – scalar, list and dict.

  1. Scalar (Identifier: $) – The most common way to use variables in Robot Framework test data is using the scalar variable syntax like ${var}. When this syntax is used, the variable name is replaced with its value as-is.

  2. List (Identifier: @) – If a variable value is a list or list-like, a list variable like @{EXAMPLE} is used. In this case, the list is expanded and individual items are passed in as separate arguments.

  3. Dictionary (Identifier: &) – A variable containing a Python dictionary or a dictionary-like object can be used as a dictionary variable like &{EXAMPLE}. In practice, this means that the dictionary is expanded and individual items are passed as named arguments to the keyword.

  4. Environment (Identifier: %) – Robot Framework allows using environment variables in the test data using the syntax %{ENV_VAR_NAME}. For example: %{PATH}. They are limited to string values.

More Topics: Assigning variablesarrow-up-right Built-in variablesarrow-up-right Runtime variablesarrow-up-right Environment variables available during a Control Room runarrow-up-right

3. Keywords

The keywords section contains operations used to execute the tests.

The different types of keywords are built-in keywords, library keywords, and user-defined keywords.

Built-in and library keywords are lower-level keywords defined by the built-in Robot Framework library or an external library such as Selenium.

User-defined keywords are keywords created by combining library keywords.

We can also pass arguments to those keywords, which make the user-defined keywords like functions that can be reused.

Keywords are organized in libraries. When you add a library, you get access to all the keywords it contains.

The Keywords section includes the Login keyword used in the test cases.

4. Test Cases

The test cases section contains the test cases. Two of the more common approaches to writing test cases are keyword-driven and Gherkin.

Keyword-driven Approach:

The keyword-driven approach uses the Robot Framework built-in keywords and keywords from an external library like Selenium.

Gherkin Approach:

The Gherkin approach uses Gherkin syntax. Gherkin is a business readable language used in behavior-driven development (BDD).

Robot Framework is case-insensitive. The keywords Close Browser and close browser are the same command

Robot framework supports keyword driven style test cases and data driven style.

Data Driven Test Cases:

Data driven works with high-level keyword used as a template to the test suite and the test cases are used to share data with the high-level keyword defined in the template. It makes the work very easy for testing UI with different inputs.

5. Test Case Tagging

Robot framework allows tagging to categorize and organize test cases.

Tags are helpful for selectively running or excluding specific test cases based on criteria such as functionality, priority, or environment

Test cases are tagged with [Tags] in square brackets, specifying one or more tags for each test case. Tags are space-separated.

In this example:

  • The Smoke Tests and Regression Tests test suites include specific test cases based on their tags.

  • You can run all tests with a specific tag using the --include command-line option, e.g., robot --include Smoke.

  • Tags can be used to group test cases based on different criteria, such as functionality (Smoke, Regression), feature (Login, Search), or priority (High, Low).

  • Tags can be assigned at the test case or suite level.

  • You can also use the --exclude option to exclude specific tags from execution.

Tags are helpful for filtering and organizing test cases, making it easier to run specific groups of tests during different phases of testing.

Tags Usage Cases:

Only execute Test cases tagged with 'Smoke' and 'Sanity' Tags:

Run all test cases except the ones with the 'Smoke' Tag:

Another way to apply tags to the test cases is by using Force Tags in the Settings section:

Syntax: Force Tags Smoke

6. Reports and Logs

Robot framework provides all the details of test suite, test case execution in the form of report and logs. All the execution details of the test case are available in the log file. The details like whether the test case has failed or passed, time taken for execution, steps followed to run the test case are provided.

7. Documentation

You can add details about your test case so that it becomes easy for future reference.

Multi-line comments:

Sample Robot Script

Project Structure

A typical Robot Framework project has the following file structure:

RIDE

This editor available with Robot framework helps in writing and running test cases.

Robot Framework Advantages

Robot framework is open source, so anyone who wants to try out can easily do so.

Robot Framework Limitations

Robot lacks support for if-else, nested loops, which are required when the code gets complex.

Running Tests

Test cases are executed with the robot command:

Robot Framework cheat sheet

Robot Framework 5 syntax recipes cheat sheet robot:arrow-up-right

Last updated