Allure Robot Framework reference
These are the attributes and methods that you can use to integrate your Robot Framework tests with Allure Report.
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
orTest 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]
orTest 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 toallure.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.
Metadata
Assign a test's description, links and other metadata.
Description
[Documentation]
For the description, Allure Robot Framework uses the scenario's [Documentation]
from the suite file.
Markdown formatting is allowed. Any HTML formatting, if present, will be stripped for security purposes.
Robot Framework*** Test Cases ***
Test Authentication
[Documentation] This test attempts to log into the website.
# ...
Owner
[Tags] allure.label.owner:⟨VALUE⟩
@allure.label('owner', value: str)
allure.dynamic.label('owner', value: str)
Set the test's owner.
Tag
[Tags]
@allure.tag(*tags: str)
allure.dynamic.tag(*tags: str)
Set the test's tags.
Any Robot Framework's native tag is automatically added to the list of the test's tags, unless it matches one of the known patterns for other labels.
Severity
[Tags] allure.label.severity:⟨VALUE⟩
@allure.severity(severity_level: str)
allure.dynamic.severity(severity_level: str)
Set the test's severity.
Allowed values are: “trivial”, “minor”, “normal”, “critical”, and “blocker”.
Label
[Tags] allure.label.⟨NAME⟩:⟨VALUE⟩
@allure.label(label_type: str, *labels: str)
allure.dynamic.label(label_type: str, *labels: str)
Set an arbitrary label for the test. This is the underlying implementation for a lot of Allure's other functions.
Allure ID (Allure TestOps)
[Tags] allure.as_id:⟨VALUE⟩
@allure.id(id: str)
Set the test's ID.
Link
[Tags] allure.link:⟨URL⟩
[Tags] allure.link.⟨NAME⟩:⟨URL⟩
[Tags] allure.issue:⟨URL⟩
[Tags] allure.issue.⟨NAME⟩:⟨URL⟩
[Tags] allure.tms:⟨URL⟩
[Tags] allure.tms.⟨NAME⟩:⟨URL⟩
allure.dynamic.link(url: str, link_type: str = LinkType.LINK, name: str = None)
allure.dynamic.issue(url: str, name: str = None)
allure.dynamic.testcase(url: str, name: str = None)
Add a link related to the test.
In a suite file, add one of the tags listed above. Each tag indicates a different link type (
link
,issue
, ortms
) which affects the icon shown in the test report.In your Python code, use the
allure.dynamic.link()
function with an optionallink_type
argument or its shorthand versions for theissue
andtms
link types.
Behavior-based hierarchy
[Tags] allure.label.epic:⟨VALUE⟩
[Tags] allure.label.feature:⟨VALUE⟩
[Tags] allure.label.story:⟨VALUE⟩
@allure.epic(*epics: str)
@allure.feature(*features: str)
@allure.story(*stories: str)
allure.dynamic.epic(*epics: str)
allure.dynamic.feature(*features: str)
allure.dynamic.story(*stories: str)
Assign names of epics, features or user stories for a test, as part of Allure's behavior-based hierarchy.
Each function support setting one or more values at once.
Suite-based hierarchy
[Tags] allure.label.parentSuite:⟨VALUE⟩
[Tags] allure.label.suite:⟨VALUE⟩
[Tags] allure.label.subSuite:⟨VALUE⟩
@allure.parent_suite(parent_suite_name: str)
@allure.suite(suite_name: str)
@allure.sub_suite(sub_suite_name: str)
allure.dynamic.parent_suite(parent_suite_name: str)
allure.dynamic.suite(suite_name: str)
allure.dynamic.sub_suite(sub_suite_name: str)
Assign the names of parent suite, suite or sub-suite for a test, as part of Allure's suite-based hierarchy.
Package-based hierarchy
[Tags] allure.label.package:⟨VALUE⟩
[Tags] allure.label.testMethod:⟨VALUE⟩
Assign the names of the package and the test method, as part of Allure's package-based hierarchy.
Test steps
@allure.step(title: str)
with allure.step(title: str)
Define a test sub-step within the current step.
There are two ways of defining a sub-step.
Decorated sub-steps
Define a function or a method containing a test sub-step and decorate it with
@allure.step()
.If the function accepts arguments, they will be displayed as step-level parameters in the test report. You can also include their values in the sub-step title via replacement fields. A replacement field is a parameter name delimited by braces
{}
, as supported by the standardstr.format()
method.Context sub-steps
Write a test sub-step in-place but use the
with allure.step()
statement to create its context.
Parametrized tests
When you pass arguments to a keyword in the suite file, Allure displays them as parameters for the corresponding step in the test report. No additional configuration is required.
Note that due to an implementation detail, Allure Report is only able to show the keyword parameters in the same way as they are given in the corresponding line. This means that if a keyword's argument is a variable (e.g., a value yielded by the Robot Framework's FOR
loop), Allure Report will display the variable's name, not the actual value it has at runtime.
The example below avoid the issue by implementing a user keyword with arguments and then using it with literal values without loops.
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
Attachments
Allure Robot Framework provides multiple ways for adding attachments to the current step.
Attaching content from variables
Attach ⟨CONTENT⟩
Attach ⟨CONTENT⟩ name=⟨NAME⟩ attachment_type=⟨TYPE⟩
allure.attach(body, name=None, attachment_type="text/plain", extension="attach")
Add body
as an attachment to the test result under the given name
(defaults to a unique pseudo-random string). The body
must be of type bytes
or str
.
To ensure that the reader's web browser will display attachments correctly, it is recommended to specify each attachment's type. There are two ways to do this:
Pass the MIME type of the content as
attachment_type
and, optionally, a filename extension asextension
.Some popular MIME types are
image/png
andimage/jpeg
for screenshots and other images,application/json
for JSON data, andtext/plain
for text files. The MIME type affects how the data will be displayed in the test report, while the filename extension is appended to the filename when user wants to save the file.Pass a value from the
allure.attachment_type
class asattachment_type
.This will automatically set the MIME type and the appropriate filename extension.
Reading attachments from files
Attach File ⟨FILE⟩
Attach File ⟨FILE⟩ name=⟨NAME⟩ attachment_type=⟨TYPE⟩
allure.attach.file(source, name=None, attachment_type=None, extension=None)
Same as Attaching content from variables, but the content is loaded from an existing file.
Attaching log messages
By default, Allure Robot Framework automatically creates a text attachment containing the log messages that occurred during a given sub-step.
This behavior can be changed, see the ALLURE_MAX_STEP_MESSAGE_COUNT
environment variable.