Allure Robot Framework

Allure Robot Framework pypi latest version

Generate beautiful HTML reports using Allure Report and your Robot Framework tests.

Allure Report Robot Framework Example

How to start

1. Prepare your project

  1. Install the Allure Report command-line tool, if it is not yet installed in your operating system. Note that Allure Report requires Java, see the installation instructions.

  2. Open a terminal and go to the project directory. For example:

    Bash
    cd /home/user/myproject
  3. If necessary for your system configuration, activate the virtual Python environment for your project.

    For example, if the project uses a venv environment, the command to activate it may look like this:

    Bash
    source .venv/bin/activate

    This step is not necessary if you are using the system Python environment.

  4. Install the Allure Robot Framework adapter.

    Bash
    pip install allure-robotframework

2. Run tests

When running your tests, add the --listener allure_robotframework command-line argument. This will allow Allure Robot Framework to collect test results into the output/allure directory. To specify another path for the test results directory, add it after the listener name, separated by a colon.

If you are going to use the test plans, also add the --prerunmodifier allure_robotframework.testplan argument.

Bash
python -m robot \ --listener allure_robotframework \ --prerunmodifier allure_robotframework.testplan \ ./my_tests
Bash
python -m robot \ --listener allure_robotframework:allure-results \ --prerunmodifier allure_robotframework.testplan \ ./my_tests

3. Generate a report

Finally, convert the test results into an HTML report. This can be done by one of two commands (replace output/allure with your path to test results):

  • allure generate output/allure processes the test results and saves an HTML report into the allure-report directory. To view the report, use the allure open command.

    Use this command if you need to save the report for future reference or for sharing it with colleagues.

  • allure serve output/allure creates the same report as allure generate output/allure but puts it into a temporary directory and starts a local web server configured to show this directory's contents. The command then automatically opens the main page of the report in a web browser.

    Use this command if you need to view the report for yourself and do not need to save it.

Writing tests

The Allure Robot Framework adapter extends the standard reporting features of Robot Framework by providing additional capabilities for crafting more informative and structured tests. This section highlights key enhancements that can be utilized:

In most cases, you need to indicate to Allure Robot Framework that a certain property needs to be assigned to the test result. Most properties can be assigned in the suite file, via the Decorators API or via the Runtime API.

  • Suite file: use the [Tags], Set Tags or Test Tags keywords in the suite files (see Tagging test cases in the Robot Framework documentation) to assign various data to tests.

    When using the [Tags] or Test Tags keyword, the data is guaranteed to be added to the test result regardless of how the test itself runs.

    When using the Set Tags keyword, it is recommended to put it as close to the beginning of the test as possible. This way, the data will be added even if the test fails early.

    You can use either a colon or an equal sign to separate the value from the name, e.g., allure.label.epic:Web interface is identical to allure.label.epic=Web interface.

  • Decorators API: add a Python decorator to a method that implements a Robot Framework keyword. When using this approach, the data is guaranteed to be added regardless of how the keyword itself runs.

  • Runtime API: use Allure's functions to add data to the test result during the execution of a keyword. This approach allows for constructing the data dynamically.

    Note that it is recommended to call the Allure's functions as close to the beginning of the implementation as possible, e.g., in the first lines of the first keyword's implementation. This way, the data will be added even if the test fails early.

There is a lot of metadata you can add to each test so that it would appear in the report. See the reference for more details.

Robot Framework
*** Test Cases *** Test Authentication [Tags] ... allure.label.owner:John Doe ... allure.label.severity:critical # ...
Python
import allure from robot.api.deco import keyword @keyword('Test Authentication') @allure.label('owner', 'John Doe') @allure.severity('critical') def test_authentication(): ...
Python
import allure from robot.api.deco import keyword @keyword('Test Authentication') def test_authentication(): allure.dynamic.label('owner', 'John Doe') allure.dynamic.severity('critical') ...

Organize tests

As described in Improving navigation in your test report, Allure supports multiple ways to organize tests into hierarchical structures. Allure Robot Framework provides functions to assign the relevant fields to tests either by adding decorators or “dynamically” (same as for the metadata fields).

To specify a test's location in the behavior-based hierarchy:

Robot Framework
*** Test Cases *** Test Authentication [Tags] ... allure.label.epic:Web interface ... allure.label.feature:Essential features ... allure.label.story:Authentication # ...
Python
import allure from robot.api.deco import keyword @keyword('Test Authentication') @allure.epic('Web interface') @allure.feature('Essential features') @allure.story('Authentication') def test_authentication(): ...
Python
import allure from robot.api.deco import keyword @keyword('Test Authentication') def test_authentication(): allure.dynamic.epic('Web interface') allure.dynamic.feature('Essential features') allure.dynamic.story('Authentication') ...

To specify a test's location in the suite-based hierarchy:

Robot Framework
*** Test Cases *** Test Authentication [Tags] ... allure.label.parentSuite:Web interface ... allure.label.suite:Essential features ... allure.label.subSuite:Authentication # ...
Python
import allure from robot.api.deco import keyword @keyword('Test Authentication') @allure.parent_suite('Web interface') @allure.suite('Essential features') @allure.sub_suite('Authentication') def test_authentication(): ...
Python
import allure from robot.api.deco import keyword @keyword('Test Authentication') def test_authentication(): allure.dynamic.parent_suite('Web interface') allure.dynamic.suite('Essential features') allure.dynamic.sub_suite('Authentication') ...

To specify a test's location in the package-based hierarchy:

Robot Framework
*** Test Cases *** Test Authentication [Tags] ... allure.label.package:org.example ... allure.label.testMethod:test_authentication() # ...
Python
import allure from robot.api.deco import keyword @keyword('Test Authentication') @allure.label('package', 'org.example') @allure.label('testMethod', 'test_authentication()') def test_authentication(): ...
Python
import allure from robot.api.deco import keyword @keyword('Test Authentication') def test_authentication(): allure.dynamic.label('package', 'org.example') allure.dynamic.label('testMethod', 'test_authentication()') ...

Divide keywords into steps

Allure Robot Framework displays each keyword as a separate step in the test report. It also provides two ways of creating sub-steps from within the Python code: “decorated steps” and “context steps”, see the reference.

Python
import allure from robot.api.deco import keyword @keyword('Test Authentication') def test_authentication(): navigate_to_the_website() for login, password in [['johndoe', 'qwerty'], ['janedoe', 'pass123']]: try_to_authenticate(login, password) @allure.step('Navigate to the website') def navigate_to_the_website(): ... @allure.step('Try to authenticate as {login}') def try_to_authenticate(login, password): ...
Python
import allure from robot.api.deco import keyword @keyword('Test Authentication') def test_authentication(): with allure.step('Navigate to the website'): ... for login, password in [['johndoe', 'qwerty'], ['janedoe', 'pass123']]: with allure.step(f'Try to authenticate as {login}'): ...

Describe parametrized tests

When you pass arguments to a keyword in the suite file, Allure Report displays them as parameters for the corresponding step, see the reference.

Robot Framework
*** Keywords *** Try To Authenticate [Arguments] ${login} ${password} Log To Console Trying to authenticate with ${login} and ${password}... # ... *** Test Cases *** Test Authentication Try To Authenticate [email protected] qwerty Try To Authenticate [email protected] pass123

Attach screenshots and other files

You can attach any sorts of files to your Allure report. For example, a popular way to make a report easier to understand is to attach a screenshot of the user interface at a certain point.

Allure Robot Framework provides various ways to create an attachment, both from existing files or generated dynamically, see the reference.

Robot Framework
*** Settings *** Library AllureLibrary Library RequestsLibrary *** Test Cases *** Test Authentication # ... ${response}= GET https://example.com/image.png Attach ${response.content} ... name=Image attachment_type=PNG Attach File /path/to/image.png ... name=Image attachment_type=PNG
Python
import allure import requests from robot.api.deco import keyword @keyword('Test Authentication') def test_authentication(): ... png_bytes = requests.get('https://example.com/image.png').content allure.attach(png_bytes, name='img', attachment_type=allure.attachment_type.PNG) allure.attach.file('/path/to/image.png', name='img', attachment_type=allure.attachment_type.PNG)

Select tests via a test plan file

If the --prerunmodifier allure_robotframework.testplan argument is used and the ALLURE_TESTPLAN_PATH environment variable points to an existing file, Robot Framework will only run tests listed in this file.

Here's an example of running tests according to a file named testplan.json:

Bash
export ALLURE_TESTPLAN_PATH=testplan.json python -m robot \ --listener allure_robotframework \ --prerunmodifier allure_robotframework.testplan \ ./my_tests
PowerShell
$Env:ALLURE_TESTPLAN_PATH = "testplan.json" python -m robot \ --listener allure_robotframework \ --prerunmodifier allure_robotframework.testplan \ ./my_tests

Environment information

For the main page of the report, you can collect various information about the environment in which the tests were executed.

For example, it is a good idea to use this to remember the OS version and Python version. This may help the future reader investigate bugs that are reproducible only in some environments.

Allure Report Environments Widget

To provide environment information, put a file named environment.properties into the test results directory (output/allure by default) after running the tests. See the example in Environment file.

Note that this feature should be used for properties that do not change for all tests in the report. If you have properties that can be different for different tests, consider using Parametrized tests.

Powered by
logo

Join our newsletter

Join our community

We aim to make Allure Report as reliable and user-friendly as possible, and together with the community, we're here to help when problems arise.

© 2024 Qameta Software Inc. All rights reserved.