Robot Framework is a generic open source test automation framework. In addition to introducing Robot Framework test data syntax, this demo shows how to execute test cases, how generated reports and logs look like, and how to extend the framework with custom test libraries.
Contents:
To get the demo, you can either download and extract the latest package from the GitHub or checkout the source code directly. As a result you get RobotDemo directory with several files.
Example test cases, test library used by them, and generated results are available also online. Therefore, you do not need to download the demo if you are not interested in running it yourself.
The demo application is a very simple calculator implemented with Python (calculator.py). It contains only business logic and no user interface. You cannot really run the calculator manually.
The demo contains three different test case files illustrating three different approaches for creating test cases with Robot Framework. Click file names below to see the latest versions online.
Example test cases using the keyword-driven testing approach.
All tests contain a workflow constructed from keywords in CalculatorLibrary.py. Creating new tests or editing existing is easy even for people without programming skills.
The keyword-driven approach works well for normal test automation, but the gherkin style might be even better if also business people need to understand tests. If the same workflow needs to repeated multiple times, it is best to use to the data-driven approach.
Example test cases using the data-driven testing approach.
The data-driven style works well when you need to repeat the same workflow multiple times.
Tests use Calculate keyword created in this file, that in turn uses keywords in CalculatorLibrary.py. An exception is the last test that has a custom template keyword.
Example test case using the gherkin syntax.
This test has a workflow similar to the keyword-driven examples. The difference is that the keywords use higher abstraction level and their arguments are embedded into the keyword names.
This kind of gherkin syntax has been made popular by Cucumber. It works well especially when tests act as examples that need to be easily understood also by the business people.
As you can see, creating test cases with Robot Framework is very easy. See Robot Framework User Guide for details about the test data syntax.
All test cases interact with the calculator using a custom test library named CalculatorLibrary.py. In practice the library is just a Python class with methods that create the keywords used by the test cases.
Generated library documentation makes it easy to see what keywords the library provides. This documentation is created with Libdoc tool integrated with the framework:
As you can see, Robot Framework's test library API is very simple. See Robot Framework User Guide for more information about creating test libraries, using Libdoc, and so on.
After running tests, you will get report and log in HTML format. Example files are also visible online in case you are not interested in running the demo yourself. Notice that one of the test has failed on purpose to show how failures look like.
A precondition for running the tests is having Robot Framework installed. It is most commonly used on Python but it works also with Jython (JVM) and IronPython (.NET). Robot Framework installation instructions cover installation procedure in detail. People already familiar with installing Python packages and having pip package manager installed, can simply run the following command:
pip install robotframework
Robot Framework 3.0 and newer support Python 3 in addition to Python 2. Also this demo project is nowadays Python 3 compatible.
Test cases are executed with the robot command:
robot keyword_driven.robot
Note
If you are using Robot Framework 2.9 or earlier, you need to use Python interpreter specific command pybot, jybot or ipybot instead.
To execute all test case files in a directory recursively, just give the directory as an argument. You can also give multiple files or directories in one go and use various command line options supported by Robot Framework. The results available online were created using the following command:
robot --name Robot --loglevel DEBUG keyword_driven.robot data_driven.robot gherkin.robot
Run robot --help for more information about the command line usage and see Robot Framework User Guide for more details about test execution in general.