robot.result package

Implements parsing execution results from XML output files.

The main public API of this package consists of the ExecutionResult() factory method, that returns Result objects, and of the ResultVisitor abstract class, that eases further processing the results. It is recommended to import these public entry-points via the robot.api package like in the example below.

The model objects defined in the robot.result.model module are also part of the public API. They are used inside the Result object, and they can also be inspected and modified as part of the normal test execution by using pre-Rebot modifiers and listeners. These model objects are not exposed via robot.api, but they can be imported from robot.result if needed.

Example

#!/usr/bin/env python

"""Usage: check_test_times.py seconds inpath [outpath]

Reads test execution result from an output XML file and checks that no test
took longer than given amount of seconds to execute.

Optional `outpath` specifies where to write processed results. If not given,
results are written over the original file.
"""

import sys
from robot.api import ExecutionResult, ResultVisitor
from robot.result.model import TestCase


class ExecutionTimeChecker(ResultVisitor):

    def __init__(self, max_seconds: float):
        self.max_milliseconds = max_seconds * 1000

    def visit_test(self, test: TestCase):
        if test.status == 'PASS' and test.elapsedtime > self.max_milliseconds:
            test.status = 'FAIL'
            test.message = 'Test execution took too long.'


def check_tests(seconds, inpath, outpath=None):
    result = ExecutionResult(inpath)
    result.visit(ExecutionTimeChecker(float(seconds)))
    result.save(outpath)


if __name__ == '__main__':
    try:
        check_tests(*sys.argv[1:])
    except TypeError:
        print(__doc__)

Submodules

robot.result.configurer module

class robot.result.configurer.SuiteConfigurer(remove_keywords=None, log_level=None, start_time=None, end_time=None, **base_config)[source]

Bases: SuiteConfigurer

Result suite configured.

Calls suite’s remove_keywords() and filter_messages() methods and sets its start and end time based on the given named parameters.

base_config is forwarded to robot.model.SuiteConfigurer that will do further configuration based on them.

visit_suite(suite)[source]

Implements traversing through suites.

Can be overridden to allow modifying the passed in suite without calling start_suite() or end_suite() nor visiting child suites, tests or setup and teardown at all.

robot.result.executionerrors module

class robot.result.executionerrors.ExecutionErrors(messages=None)[source]

Bases: object

Represents errors occurred during the execution of tests.

An error might be, for example, that importing a library has failed.

id = 'errors'
messages

A list-like object of Message instances.

add(other)[source]
visit(visitor)[source]

robot.result.executionresult module

robot.result.executionresult.is_json_source(source)[source]
class robot.result.executionresult.Result(source=None, root_suite=None, errors=None, rpa=None)[source]

Bases: object

Test execution results.

Can be created based on XML output files using the ExecutionResult() factory method. Also returned by the robot.running.TestSuite.run method.

source

Path to the XML file where results are read from.

suite

Hierarchical execution results as a TestSuite object.

errors

Execution errors as an ExecutionErrors object.

property statistics

Test execution statistics.

Statistics are an instance of Statistics that is created based on the contained suite and possible configuration.

Statistics are created every time this property is accessed. Saving them to a variable is thus often a good idea to avoid re-creating them unnecessarily:

from robot.api import ExecutionResult

result = ExecutionResult('output.xml')
result.configure(stat_config={'suite_stat_level': 2,
                              'tag_stat_combine': 'tagANDanother'})
stats = result.statistics
print(stats.total.failed)
print(stats.total.passed)
print(stats.tags.combined[0].total)
property return_code

Return code (integer) of test execution.

By default returns the number of failed tests (max 250), but can be configured to always return 0.

configure(status_rc=True, suite_config=None, stat_config=None)[source]

Configures the result object and objects it contains.

Parameters:
  • status_rc – If set to False, return_code always returns 0.

  • suite_config – A dictionary of configuration options passed to configure() method of the contained suite.

  • stat_config – A dictionary of configuration options used when creating statistics.

save(target=None, legacy_output=False)[source]

Save results as XML or JSON file.

Parameters:
  • target – Target where to save results to. Can be a path (pathlib.Path or str) or an open file object. If omitted, uses the source which overwrites the original file.

  • legacy_output – Save result in Robot Framework 6.x compatible format. New in Robot Framework 7.0.

File type is got based on the target. The type is JSON if the target is a path that has a .json suffix or if it is an open file that has a name attribute with a .json suffix. Otherwise, the type is XML.

Notice that saved JSON files only contain suite information, no statics or errors like XML files. This is likely to change in the future so that JSON files get a new root object with the current suite as a child and statics and errors as additional children. Robot Framework’s own functions and methods accepting JSON results will continue to work also with JSON files containing only a suite.

visit(visitor)[source]

An entry point to visit the whole result object.

Parameters:

visitor – An instance of ResultVisitor.

Visitors can gather information, modify results, etc. See result package for a simple usage example.

Notice that it is also possible to call result.suite.visit if there is no need to visit the contained statistics or errors.

handle_suite_teardown_failures()[source]

Internal usage only.

set_execution_mode(other)[source]

Set execution mode based on other result. Internal usage only.

class robot.result.executionresult.CombinedResult(results=None)[source]

Bases: Result

Combined results of multiple test executions.

add_result(other)[source]

robot.result.flattenkeywordmatcher module

robot.result.flattenkeywordmatcher.validate_flatten_keyword(options)[source]
robot.result.flattenkeywordmatcher.create_flatten_message(original)[source]
class robot.result.flattenkeywordmatcher.FlattenByTypeMatcher(flatten)[source]

Bases: object

match(tag)[source]
class robot.result.flattenkeywordmatcher.FlattenByNameMatcher(flatten)[source]

Bases: object

match(name, owner=None)[source]
class robot.result.flattenkeywordmatcher.FlattenByTagMatcher(flatten)[source]

Bases: object

match(tags)[source]
class robot.result.flattenkeywordmatcher.FlattenByTags(flatten)[source]

Bases: SuiteVisitor

start_suite(suite)[source]

Called when a suite starts. Default implementation does nothing.

Can return explicit False to stop visiting.

start_keyword(keyword: Keyword)[source]

Called when a keyword starts.

By default, calls start_body_item() which, by default, does nothing.

Can return explicit False to stop visiting.

class robot.result.flattenkeywordmatcher.MessageFinder(keyword: Keyword)[source]

Bases: SuiteVisitor

visit_message(message)[source]

Implements visiting messages.

Can be overridden to allow modifying the passed in msg without calling start_message() or end_message().

robot.result.keywordremover module

class robot.result.keywordremover.KeywordRemover[source]

Bases: SuiteVisitor, ABC

message = 'Content removed using the --remove-keywords option.'
classmethod from_config(conf)[source]
class robot.result.keywordremover.AllKeywordsRemover[source]

Bases: KeywordRemover

start_body_item(item)[source]

Called, by default, when keywords, messages or control structures start.

More specific start_keyword(), start_message(), :meth:`start_for, etc. can be implemented to visit only keywords, messages or specific control structures.

Can return explicit False to stop visiting. Default implementation does nothing.

start_if(item)[source]

Called when an IF/ELSE structure starts.

By default, calls start_body_item() which, by default, does nothing.

Can return explicit False to stop visiting.

start_if_branch(item)[source]

Called when an IF/ELSE branch starts.

By default, calls start_body_item() which, by default, does nothing.

Can return explicit False to stop visiting.

start_try(item)[source]

Called when a TRY/EXCEPT structure starts.

By default, calls start_body_item() which, by default, does nothing.

Can return explicit False to stop visiting.

start_try_branch(item)[source]

Called when TRY, EXCEPT, ELSE or FINALLY branches start.

By default, calls start_body_item() which, by default, does nothing.

Can return explicit False to stop visiting.

class robot.result.keywordremover.PassedKeywordRemover[source]

Bases: KeywordRemover

start_suite(suite)[source]

Called when a suite starts. Default implementation does nothing.

Can return explicit False to stop visiting.

visit_test(test)[source]

Implements traversing through tests.

Can be overridden to allow modifying the passed in test without calling start_test() or end_test() nor visiting the body of the test.

visit_keyword(keyword)[source]

Implements traversing through keywords.

Can be overridden to allow modifying the passed in kw without calling start_keyword() or end_keyword() nor visiting the body of the keyword

class robot.result.keywordremover.ByNameKeywordRemover(pattern)[source]

Bases: KeywordRemover

start_keyword(kw)[source]

Called when a keyword starts.

By default, calls start_body_item() which, by default, does nothing.

Can return explicit False to stop visiting.

class robot.result.keywordremover.ByTagKeywordRemover(pattern)[source]

Bases: KeywordRemover

start_keyword(kw)[source]

Called when a keyword starts.

By default, calls start_body_item() which, by default, does nothing.

Can return explicit False to stop visiting.

class robot.result.keywordremover.LoopItemsRemover[source]

Bases: KeywordRemover, ABC

message = '{count} passing item{s} removed using the --remove-keywords option.'
class robot.result.keywordremover.ForLoopItemsRemover[source]

Bases: LoopItemsRemover

start_for(for_)[source]

Called when a FOR loop starts.

By default, calls start_body_item() which, by default, does nothing.

Can return explicit False to stop visiting.

class robot.result.keywordremover.WhileLoopItemsRemover[source]

Bases: LoopItemsRemover

start_while(while_)[source]

Called when a WHILE loop starts.

By default, calls start_body_item() which, by default, does nothing.

Can return explicit False to stop visiting.

class robot.result.keywordremover.WaitUntilKeywordSucceedsRemover[source]

Bases: KeywordRemover

message = '{count} failing item{s} removed using the --remove-keywords option.'
start_keyword(kw)[source]

Called when a keyword starts.

By default, calls start_body_item() which, by default, does nothing.

Can return explicit False to stop visiting.

class robot.result.keywordremover.WarningAndErrorFinder[source]

Bases: SuiteVisitor

start_suite(suite)[source]

Called when a suite starts. Default implementation does nothing.

Can return explicit False to stop visiting.

start_test(test)[source]

Called when a test starts. Default implementation does nothing.

Can return explicit False to stop visiting.

start_keyword(keyword)[source]

Called when a keyword starts.

By default, calls start_body_item() which, by default, does nothing.

Can return explicit False to stop visiting.

visit_message(msg)[source]

Implements visiting messages.

Can be overridden to allow modifying the passed in msg without calling start_message() or end_message().

class robot.result.keywordremover.RemovalMessage(message)[source]

Bases: object

set_to_if_removed(item, len_before)[source]
set_to(item, message=None)[source]

robot.result.merger module

class robot.result.merger.Merger(result, rpa=False)[source]

Bases: SuiteVisitor

merge(merged)[source]
start_suite(suite)[source]

Called when a suite starts. Default implementation does nothing.

Can return explicit False to stop visiting.

end_suite(suite)[source]

Called when a suite ends. Default implementation does nothing.

visit_test(test)[source]

Implements traversing through tests.

Can be overridden to allow modifying the passed in test without calling start_test() or end_test() nor visiting the body of the test.

robot.result.messagefilter module

class robot.result.messagefilter.MessageFilter(log_level=None)[source]

Bases: SuiteVisitor

start_suite(suite)[source]

Called when a suite starts. Default implementation does nothing.

Can return explicit False to stop visiting.

start_keyword(keyword)[source]

Called when a keyword starts.

By default, calls start_body_item() which, by default, does nothing.

Can return explicit False to stop visiting.

robot.result.model module

Module implementing result related model objects.

During test execution these objects are created internally by various runners. At that time they can be inspected and modified by listeners.

When results are parsed from XML output files after execution to be able to create logs and reports, these objects are created by the ExecutionResult() factory method. At that point they can be inspected and modified by pre-Rebot modifiers.

The ExecutionResult() factory method can also be used by custom scripts and tools. In such usage it is often easiest to inspect and modify these objects using the visitor interface.

If classes defined here are needed, for example, as type hints, they can be imported via the robot.running module.

class robot.result.model.Body(parent: TestSuite | TestCase | UserKeyword | For | ForIteration | If | IfBranch | Try | TryBranch | While | WhileIteration | Keyword | Var | Return | Continue | Break | Error | None = None, items: Iterable[BodyItem | DataDict] = ())[source]

Bases: BaseBody[Keyword, For, While, If, Try, Var, Return, Continue, Break, Message, Error]

break_class

alias of Break

continue_class

alias of Continue

error_class

alias of Error

for_class

alias of For

if_class

alias of If

keyword_class

alias of Keyword

message_class

alias of Message

return_class

alias of Return

try_class

alias of Try

var_class

alias of Var

while_class

alias of While

class robot.result.model.Branches(branch_class: Type[IT], parent: TestSuite | TestCase | UserKeyword | For | ForIteration | If | IfBranch | Try | TryBranch | While | WhileIteration | Keyword | Var | Return | Continue | Break | Error | None = None, items: Iterable[IT | DataDict] = ())[source]

Bases: BaseBranches[Keyword, For, While, If, Try, Var, Return, Continue, Break, Message, Error, IT]

keyword_class

alias of Keyword

message_class

alias of Message

class robot.result.model.Iterations(iteration_class: Type[FW], parent: TestSuite | TestCase | UserKeyword | For | ForIteration | If | IfBranch | Try | TryBranch | While | WhileIteration | Keyword | Var | Return | Continue | Break | Error | None = None, items: Iterable[FW | DataDict] = ())[source]

Bases: BaseIterations[Keyword, For, While, If, Try, Var, Return, Continue, Break, Message, Error, FW]

keyword_class

alias of Keyword

message_class

alias of Message

class robot.result.model.Message(message: str = '', level: Literal['TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FAIL', 'SKIP'] = 'INFO', html: bool = False, timestamp: datetime | str | None = None, parent: BodyItem | None = None)[source]

Bases: Message

to_dict() Dict[str, Any][source]

Serialize this object into a dictionary.

The object can be later restored by using the from_dict() method.

With robot.running model objects new in Robot Framework 6.1, with robot.result new in Robot Framework 7.0.

class robot.result.model.StatusMixin[source]

Bases: object

PASS = 'PASS'
FAIL = 'FAIL'
SKIP = 'SKIP'
NOT_RUN = 'NOT RUN'
NOT_SET = 'NOT SET'
status: Literal['PASS', 'FAIL', 'SKIP', 'NOT RUN', 'NOT SET']
property start_time: datetime | None

Execution start time as a datetime or as a None if not set.

If start time is not set, it is calculated based end_time and elapsed_time if possible.

Can be set either directly as a datetime or as a string in ISO 8601 format.

New in Robot Framework 6.1. Heavily enhanced in Robot Framework 7.0.

property end_time: datetime | None

Execution end time as a datetime or as a None if not set.

If end time is not set, it is calculated based start_time and elapsed_time if possible.

Can be set either directly as a datetime or as a string in ISO 8601 format.

New in Robot Framework 6.1. Heavily enhanced in Robot Framework 7.0.

property elapsed_time: timedelta

Total execution time as a timedelta.

If not set, calculated based on start_time and end_time if possible. If that fails, calculated based on the elapsed time of child items.

Can be set either directly as a timedelta or as an integer or a float representing seconds.

New in Robot Framework 6.1. Heavily enhanced in Robot Framework 7.0.

property starttime: str | None

Execution start time as a string or as a None if not set.

The string format is %Y%m%d %H:%M:%S.%f.

Considered deprecated starting from Robot Framework 7.0. start_time should be used instead.

property endtime: str | None

Execution end time as a string or as a None if not set.

The string format is %Y%m%d %H:%M:%S.%f.

Considered deprecated starting from Robot Framework 7.0. end_time should be used instead.

property elapsedtime: int

Total execution time in milliseconds.

Considered deprecated starting from Robot Framework 7.0. elapsed_time should be used instead.

property passed: bool

True when status is ‘PASS’, False otherwise.

property failed: bool

True when status is ‘FAIL’, False otherwise.

property skipped: bool

True when status is ‘SKIP’, False otherwise.

Setting to False value is ambiguous and raises an exception.

property not_run: bool

True when status is ‘NOT RUN’, False otherwise.

Setting to False value is ambiguous and raises an exception.

to_dict()[source]
class robot.result.model.ForIteration(assign: Mapping[str, str] | None = None, status: str = 'FAIL', message: str = '', start_time: datetime | str | None = None, end_time: datetime | str | None = None, elapsed_time: timedelta | int | float | None = None, parent: TestSuite | TestCase | Keyword | For | ForIteration | If | IfBranch | Try | TryBranch | While | WhileIteration | None = None)[source]

Bases: ForIteration, StatusMixin, DeprecatedAttributesMixin

body_class

alias of Body

status: Literal['PASS', 'FAIL', 'SKIP', 'NOT RUN', 'NOT SET']
message
to_dict() Dict[str, Any][source]

Serialize this object into a dictionary.

The object can be later restored by using the from_dict() method.

With robot.running model objects new in Robot Framework 6.1, with robot.result new in Robot Framework 7.0.

assign
class robot.result.model.For(assign: Sequence[str] = (), flavor: Literal['IN', 'IN RANGE', 'IN ENUMERATE', 'IN ZIP'] = 'IN', values: Sequence[str] = (), start: str | None = None, mode: str | None = None, fill: str | None = None, status: str = 'FAIL', message: str = '', start_time: datetime | str | None = None, end_time: datetime | str | None = None, elapsed_time: timedelta | int | float | None = None, parent: TestSuite | TestCase | Keyword | For | ForIteration | If | IfBranch | Try | TryBranch | While | WhileIteration | None = None)[source]

Bases: For, StatusMixin, DeprecatedAttributesMixin

iteration_class

alias of ForIteration

iterations_class

alias of Iterations[ForIteration]

status: Literal['PASS', 'FAIL', 'SKIP', 'NOT RUN', 'NOT SET']
message
body
to_dict() Dict[str, Any][source]

Serialize this object into a dictionary.

The object can be later restored by using the from_dict() method.

With robot.running model objects new in Robot Framework 6.1, with robot.result new in Robot Framework 7.0.

class robot.result.model.WhileIteration(status: str = 'FAIL', message: str = '', start_time: datetime | str | None = None, end_time: datetime | str | None = None, elapsed_time: timedelta | int | float | None = None, parent: TestSuite | TestCase | Keyword | For | ForIteration | If | IfBranch | Try | TryBranch | While | WhileIteration | None = None)[source]

Bases: WhileIteration, StatusMixin, DeprecatedAttributesMixin

body_class

alias of Body

status: Literal['PASS', 'FAIL', 'SKIP', 'NOT RUN', 'NOT SET']
message
to_dict() Dict[str, Any][source]

Serialize this object into a dictionary.

The object can be later restored by using the from_dict() method.

With robot.running model objects new in Robot Framework 6.1, with robot.result new in Robot Framework 7.0.

class robot.result.model.While(condition: str | None = None, limit: str | None = None, on_limit: str | None = None, on_limit_message: str | None = None, status: str = 'FAIL', message: str = '', start_time: datetime | str | None = None, end_time: datetime | str | None = None, elapsed_time: timedelta | int | float | None = None, parent: TestSuite | TestCase | Keyword | For | ForIteration | If | IfBranch | Try | TryBranch | While | WhileIteration | None = None)[source]

Bases: While, StatusMixin, DeprecatedAttributesMixin

iteration_class

alias of WhileIteration

iterations_class

alias of Iterations[WhileIteration]

status: Literal['PASS', 'FAIL', 'SKIP', 'NOT RUN', 'NOT SET']
message
body
to_dict() Dict[str, Any][source]

Serialize this object into a dictionary.

The object can be later restored by using the from_dict() method.

With robot.running model objects new in Robot Framework 6.1, with robot.result new in Robot Framework 7.0.

class robot.result.model.IfBranch(type: str = 'IF', condition: str | None = None, status: str = 'FAIL', message: str = '', start_time: datetime | str | None = None, end_time: datetime | str | None = None, elapsed_time: timedelta | int | float | None = None, parent: TestSuite | TestCase | Keyword | For | ForIteration | If | IfBranch | Try | TryBranch | While | WhileIteration | None = None)[source]

Bases: IfBranch, StatusMixin, DeprecatedAttributesMixin

body_class

alias of Body

status: Literal['PASS', 'FAIL', 'SKIP', 'NOT RUN', 'NOT SET']
message
to_dict() Dict[str, Any][source]

Serialize this object into a dictionary.

The object can be later restored by using the from_dict() method.

With robot.running model objects new in Robot Framework 6.1, with robot.result new in Robot Framework 7.0.

class robot.result.model.If(status: str = 'FAIL', message: str = '', start_time: datetime | str | None = None, end_time: datetime | str | None = None, elapsed_time: timedelta | int | float | None = None, parent: TestSuite | TestCase | Keyword | For | ForIteration | If | IfBranch | Try | TryBranch | While | WhileIteration | None = None)[source]

Bases: If, StatusMixin, DeprecatedAttributesMixin

branch_class

alias of IfBranch

branches_class

alias of Branches[IfBranch]

status: Literal['PASS', 'FAIL', 'SKIP', 'NOT RUN', 'NOT SET']
message
to_dict() Dict[str, Any][source]

Serialize this object into a dictionary.

The object can be later restored by using the from_dict() method.

With robot.running model objects new in Robot Framework 6.1, with robot.result new in Robot Framework 7.0.

class robot.result.model.TryBranch(type: str = 'TRY', patterns: Sequence[str] = (), pattern_type: str | None = None, assign: str | None = None, status: str = 'FAIL', message: str = '', start_time: datetime | str | None = None, end_time: datetime | str | None = None, elapsed_time: timedelta | int | float | None = None, parent: TestSuite | TestCase | Keyword | For | ForIteration | If | IfBranch | Try | TryBranch | While | WhileIteration | None = None)[source]

Bases: TryBranch, StatusMixin, DeprecatedAttributesMixin

body_class

alias of Body

status: Literal['PASS', 'FAIL', 'SKIP', 'NOT RUN', 'NOT SET']
message
to_dict() Dict[str, Any][source]

Serialize this object into a dictionary.

The object can be later restored by using the from_dict() method.

With robot.running model objects new in Robot Framework 6.1, with robot.result new in Robot Framework 7.0.

class robot.result.model.Try(status: str = 'FAIL', message: str = '', start_time: datetime | str | None = None, end_time: datetime | str | None = None, elapsed_time: timedelta | int | float | None = None, parent: TestSuite | TestCase | Keyword | For | ForIteration | If | IfBranch | Try | TryBranch | While | WhileIteration | None = None)[source]

Bases: Try, StatusMixin, DeprecatedAttributesMixin

branch_class

alias of TryBranch

branches_class

alias of Branches[TryBranch]

status: Literal['PASS', 'FAIL', 'SKIP', 'NOT RUN', 'NOT SET']
message
to_dict() Dict[str, Any][source]

Serialize this object into a dictionary.

The object can be later restored by using the from_dict() method.

With robot.running model objects new in Robot Framework 6.1, with robot.result new in Robot Framework 7.0.

class robot.result.model.Var(name: str = '', value: str | Sequence[str] = (), scope: str | None = None, separator: str | None = None, status: str = 'FAIL', message: str = '', start_time: datetime | str | None = None, end_time: datetime | str | None = None, elapsed_time: timedelta | int | float | None = None, parent: TestSuite | TestCase | Keyword | For | ForIteration | If | IfBranch | Try | TryBranch | While | WhileIteration | None = None)[source]

Bases: Var, StatusMixin, DeprecatedAttributesMixin

body_class

alias of Body

status: Literal['PASS', 'FAIL', 'SKIP', 'NOT RUN', 'NOT SET']
message
body

Child keywords and messages as a Body object.

Typically empty. Only contains something if running VAR has failed due to a syntax error or listeners have logged messages or executed keywords.

to_dict() Dict[str, Any][source]

Serialize this object into a dictionary.

The object can be later restored by using the from_dict() method.

With robot.running model objects new in Robot Framework 6.1, with robot.result new in Robot Framework 7.0.

class robot.result.model.Return(values: Sequence[str] = (), status: str = 'FAIL', message: str = '', start_time: datetime | str | None = None, end_time: datetime | str | None = None, elapsed_time: timedelta | int | float | None = None, parent: TestSuite | TestCase | Keyword | For | ForIteration | If | IfBranch | Try | TryBranch | While | WhileIteration | None = None)[source]

Bases: Return, StatusMixin, DeprecatedAttributesMixin

body_class

alias of Body

status: Literal['PASS', 'FAIL', 'SKIP', 'NOT RUN', 'NOT SET']
message
body

Child keywords and messages as a Body object.

Typically empty. Only contains something if running RETURN has failed due to a syntax error or listeners have logged messages or executed keywords.

to_dict() Dict[str, Any][source]

Serialize this object into a dictionary.

The object can be later restored by using the from_dict() method.

With robot.running model objects new in Robot Framework 6.1, with robot.result new in Robot Framework 7.0.

class robot.result.model.Continue(status: str = 'FAIL', message: str = '', start_time: datetime | str | None = None, end_time: datetime | str | None = None, elapsed_time: timedelta | int | float | None = None, parent: TestSuite | TestCase | Keyword | For | ForIteration | If | IfBranch | Try | TryBranch | While | WhileIteration | None = None)[source]

Bases: Continue, StatusMixin, DeprecatedAttributesMixin

body_class

alias of Body

status: Literal['PASS', 'FAIL', 'SKIP', 'NOT RUN', 'NOT SET']
message
body

Child keywords and messages as a Body object.

Typically empty. Only contains something if running CONTINUE has failed due to a syntax error or listeners have logged messages or executed keywords.

to_dict() Dict[str, Any][source]

Serialize this object into a dictionary.

The object can be later restored by using the from_dict() method.

With robot.running model objects new in Robot Framework 6.1, with robot.result new in Robot Framework 7.0.

class robot.result.model.Break(status: str = 'FAIL', message: str = '', start_time: datetime | str | None = None, end_time: datetime | str | None = None, elapsed_time: timedelta | int | float | None = None, parent: TestSuite | TestCase | Keyword | For | ForIteration | If | IfBranch | Try | TryBranch | While | WhileIteration | None = None)[source]

Bases: Break, StatusMixin, DeprecatedAttributesMixin

body_class

alias of Body

status: Literal['PASS', 'FAIL', 'SKIP', 'NOT RUN', 'NOT SET']
message
body

Child keywords and messages as a Body object.

Typically empty. Only contains something if running BREAK has failed due to a syntax error or listeners have logged messages or executed keywords.

to_dict() Dict[str, Any][source]

Serialize this object into a dictionary.

The object can be later restored by using the from_dict() method.

With robot.running model objects new in Robot Framework 6.1, with robot.result new in Robot Framework 7.0.

class robot.result.model.Error(values: Sequence[str] = (), status: str = 'FAIL', message: str = '', start_time: datetime | str | None = None, end_time: datetime | str | None = None, elapsed_time: timedelta | int | float | None = None, parent: TestSuite | TestCase | Keyword | For | ForIteration | If | IfBranch | Try | TryBranch | While | WhileIteration | None = None)[source]

Bases: Error, StatusMixin, DeprecatedAttributesMixin

body_class

alias of Body

status: Literal['PASS', 'FAIL', 'SKIP', 'NOT RUN', 'NOT SET']
message
body

Messages as a Body object.

Typically contains the message that caused the error.

to_dict() Dict[str, Any][source]

Serialize this object into a dictionary.

The object can be later restored by using the from_dict() method.

With robot.running model objects new in Robot Framework 6.1, with robot.result new in Robot Framework 7.0.

class robot.result.model.Keyword(name: str | None = '', owner: str | None = None, source_name: str | None = None, doc: str = '', args: Sequence[str] = (), assign: Sequence[str] = (), tags: Sequence[str] = (), timeout: str | None = None, type: str = 'KEYWORD', status: str = 'FAIL', message: str = '', start_time: datetime | str | None = None, end_time: datetime | str | None = None, elapsed_time: timedelta | int | float | None = None, parent: TestSuite | TestCase | Keyword | For | ForIteration | If | IfBranch | Try | TryBranch | While | WhileIteration | None = None)[source]

Bases: Keyword, StatusMixin

Represents an executed library or user keyword.

body_class

alias of Body

owner

Name of the library or resource containing this keyword.

source_name

Original name of keyword with embedded arguments.

doc
timeout
status: Literal['PASS', 'FAIL', 'SKIP', 'NOT RUN', 'NOT SET']
message
body

Possible keyword body as a Body object.

Body can consist of child keywords, messages, and control structures such as IF/ELSE. Library keywords typically have an empty body.

property messages: list[Message]

Keyword’s messages.

Starting from Robot Framework 4.0 this is a list generated from messages in body.

property full_name: str | None

Keyword name in format owner.name.

Just name if owner is not set. In practice this is the case only with user keywords in the suite file.

Cannot be set directly. Set name and owner separately instead.

Notice that prior to Robot Framework 7.0, the name attribute contained the full name and keyword and owner names were in kwname and libname, respectively.

property kwname: str | None

Deprecated since Robot Framework 7.0. Use name instead.

property libname: str | None

Deprecated since Robot Framework 7.0. Use owner instead.

property sourcename: str

Deprecated since Robot Framework 7.0. Use source_name instead.

property setup: Keyword

Keyword setup as a Keyword object.

See teardown for more information. New in Robot Framework 7.0.

property has_setup: bool

Check does a keyword have a setup without creating a setup object.

See has_teardown for more information. New in Robot Framework 7.0.

property teardown: Keyword

Keyword teardown as a Keyword object.

Teardown can be modified by setting attributes directly:

keyword.teardown.name = 'Example'
keyword.teardown.args = ('First', 'Second')

Alternatively the config() method can be used to set multiple attributes in one call:

keyword.teardown.config(name='Example', args=('First', 'Second'))

The easiest way to reset the whole teardown is setting it to None. It will automatically recreate the underlying Keyword object:

keyword.teardown = None

This attribute is a Keyword object also when a keyword has no teardown but in that case its truth value is False. If there is a need to just check does a keyword have a teardown, using the has_teardown attribute avoids creating the Keyword object and is thus more memory efficient.

New in Robot Framework 4.0. Earlier teardown was accessed like keyword.keywords.teardown. has_teardown is new in Robot Framework 4.1.2.

property has_teardown: bool

Check does a keyword have a teardown without creating a teardown object.

A difference between using if kw.has_teardown: and if kw.teardown: is that accessing the teardown attribute creates a Keyword object representing a teardown even when the keyword actually does not have one. This typically does not matter, but with bigger suite structures having lots of keywords it can have a considerable effect on memory usage.

New in Robot Framework 4.1.2.

tags

Keyword tags as a Tags object.

to_dict() Dict[str, Any][source]

Serialize this object into a dictionary.

The object can be later restored by using the from_dict() method.

With robot.running model objects new in Robot Framework 6.1, with robot.result new in Robot Framework 7.0.

class robot.result.model.TestCase(name: str = '', doc: str = '', tags: Sequence[str] = (), timeout: str | None = None, lineno: int | None = None, status: str = 'FAIL', message: str = '', start_time: datetime | str | None = None, end_time: datetime | str | None = None, elapsed_time: timedelta | int | float | None = None, parent: TestSuite | None = None)[source]

Bases: TestCase[Keyword], StatusMixin

Represents results of a single test case.

See the base class for documentation of attributes not documented here.

body_class

alias of Body

fixture_class

alias of Keyword

status: Literal['PASS', 'FAIL', 'SKIP', 'NOT RUN', 'NOT SET']
message
property not_run: bool

True when status is ‘NOT RUN’, False otherwise.

Setting to False value is ambiguous and raises an exception.

body

Test body as a Body object.

to_dict() Dict[str, Any][source]

Serialize this object into a dictionary.

The object can be later restored by using the from_dict() method.

With robot.running model objects new in Robot Framework 6.1, with robot.result new in Robot Framework 7.0.

class robot.result.model.TestSuite(name: str = '', doc: str = '', metadata: Mapping[str, str] | None = None, source: Path | str | None = None, rpa: bool = False, message: str = '', start_time: datetime | str | None = None, end_time: datetime | str | None = None, elapsed_time: timedelta | int | float | None = None, parent: TestSuite | None = None)[source]

Bases: TestSuite[Keyword, TestCase], StatusMixin

Represents results of a single test suite.

See the base class for documentation of attributes not documented here.

test_class

alias of TestCase

fixture_class

alias of Keyword

message

Possible suite setup or teardown error message.

property passed: bool

True if no test has failed but some have passed, False otherwise.

property failed: bool

True if any test has failed, False otherwise.

property skipped: bool

True if there are no passed or failed tests, False otherwise.

property not_run: bool

True when status is ‘NOT RUN’, False otherwise.

Setting to False value is ambiguous and raises an exception.

property status: Literal['PASS', 'SKIP', 'FAIL']

‘PASS’, ‘FAIL’ or ‘SKIP’ depending on test statuses.

  • If any test has failed, status is ‘FAIL’.

  • If no test has failed but at least some test has passed, status is ‘PASS’.

  • If there are no failed or passed tests, status is ‘SKIP’. This covers both the case when all tests have been skipped and when there are no tests.

property statistics: TotalStatistics

Suite statistics as a TotalStatistics object.

Recreated every time this property is accessed, so saving the results to a variable and inspecting it is often a good idea:

stats = suite.statistics
print(stats.failed)
print(stats.total)
print(stats.message)
property full_message: str

Combination of message and stat_message.

property stat_message: str

String representation of the statistics.

suites
remove_keywords(how: str)[source]

Remove keywords based on the given condition.

Parameters:

how – Which approach to use when removing keywords. Either ALL, PASSED, FOR, WUKS, or NAME:<pattern>.

For more information about the possible values see the documentation of the --removekeywords command line option.

filter_messages(log_level: str = 'TRACE')[source]

Remove log messages below the specified log_level.

configure(**options)[source]

A shortcut to configure a suite using one method call.

Can only be used with the root test suite.

Parameters:

options – Passed to SuiteConfigurer that will then set suite attributes, call filter(), etc. as needed.

Example:

suite.configure(remove_keywords='PASSED',
                doc='Smoke test results.')

Not to be confused with config() method that suites, tests, and keywords have to make it possible to set multiple attributes in one call.

handle_suite_teardown_failures()[source]

Internal usage only.

suite_teardown_failed(message: str)[source]

Internal usage only.

suite_teardown_skipped(message: str)[source]

Internal usage only.

to_dict() Dict[str, Any][source]

Serialize this object into a dictionary.

The object can be later restored by using the from_dict() method.

With robot.running model objects new in Robot Framework 6.1, with robot.result new in Robot Framework 7.0.

to_xml(file: None = None) str[source]
to_xml(file: TextIO | Path | str) None

Serialize suite into XML.

The format is the same that is used with normal output.xml files, but the <robot> root node is omitted and the result contains only the <suite> structure.

The file parameter controls what to do with the resulting XML data. It can be:

  • None (default) to return the data as a string,

  • an open file object where to write the data to, or

  • a path (pathlib.Path or string) to a file where to write the data using UTF-8 encoding.

A serialized suite can be recreated by using the from_xml() method.

New in Robot Framework 7.0.

classmethod from_xml(source: str | TextIO | Path) TestSuite[source]

Create suite based on results in XML.

The data is given as the source parameter. It can be:

  • a string containing the data directly,

  • an open file object where to read the data from, or

  • a path (pathlib.Path or string) to a UTF-8 encoded file to read.

Supports both normal output.xml files and files containing only the <suite> structure created, for example, with the to_xml() method. When using normal output.xml files, possible execution errors listed in <errors> are silently ignored. If that is a problem, ExecutionResult should be used instead.

New in Robot Framework 7.0.

robot.result.modeldeprecation module

robot.result.modeldeprecation.deprecated(method)[source]
class robot.result.modeldeprecation.DeprecatedAttributesMixin[source]

Bases: object

property name

Deprecated.

property kwname

Deprecated.

property libname

Deprecated.

property args

Deprecated.

property assign

Deprecated.

property tags

Deprecated.

property timeout

Deprecated.

property doc

Deprecated.

robot.result.resultbuilder module

robot.result.resultbuilder.ExecutionResult(*sources, **options)[source]

Factory method to constructs Result objects.

Parameters:
  • sources – XML or JSON source(s) containing execution results. Can be specified as paths (pathlib.Path or str), opened file objects, or strings/bytes containing XML/JSON directly.

  • options – Configuration options. Using merge=True causes multiple results to be combined so that tests in the latter results replace the ones in the original. Setting rpa either to True (RPA mode) or False (test automation) sets execution mode explicitly. By default, it is got from processed output files and conflicting modes cause an error. Other options are passed directly to the ExecutionResultBuilder object used internally.

Returns:

Result instance.

A source is considered to be JSON in these cases: - It is a path with a .json suffix. - It is an open file that has a name attribute with a .json suffix. - It is string or bytes starting with { and ending with }.

This method should be imported by external code via the robot.api package. See the robot.result package for a usage example.

class robot.result.resultbuilder.ExecutionResultBuilder(source, include_keywords=True, flattened_keywords=None)[source]

Bases: object

Builds Result objects based on output files.

Instead of using this builder directly, it is recommended to use the ExecutionResult() factory method.

Parameters:
  • source – Path to the XML output file to build Result objects from.

  • include_keywords – Controls whether to include keywords and control structures like FOR and IF in the result or not. They are not needed when generating only a report.

  • flattened_keywords – List of patterns controlling what keywords and control structures to flatten. See the documentation of the --flattenkeywords option for more details.

build(result)[source]
class robot.result.resultbuilder.RemoveKeywords[source]

Bases: SuiteVisitor

start_suite(suite)[source]

Called when a suite starts. Default implementation does nothing.

Can return explicit False to stop visiting.

visit_test(test)[source]

Implements traversing through tests.

Can be overridden to allow modifying the passed in test without calling start_test() or end_test() nor visiting the body of the test.

robot.result.suiteteardownfailed module

class robot.result.suiteteardownfailed.SuiteTeardownFailureHandler[source]

Bases: SuiteVisitor

end_suite(suite)[source]

Called when a suite ends. Default implementation does nothing.

visit_test(test)[source]

Implements traversing through tests.

Can be overridden to allow modifying the passed in test without calling start_test() or end_test() nor visiting the body of the test.

visit_keyword(keyword)[source]

Implements traversing through keywords.

Can be overridden to allow modifying the passed in kw without calling start_keyword() or end_keyword() nor visiting the body of the keyword

class robot.result.suiteteardownfailed.SuiteTeardownFailed(message, skipped=False)[source]

Bases: SuiteVisitor

visit_test(test)[source]

Implements traversing through tests.

Can be overridden to allow modifying the passed in test without calling start_test() or end_test() nor visiting the body of the test.

visit_keyword(keyword)[source]

Implements traversing through keywords.

Can be overridden to allow modifying the passed in kw without calling start_keyword() or end_keyword() nor visiting the body of the keyword

robot.result.visitor module

Visitors can be used to easily traverse result structures.

This module contains ResultVisitor for traversing the whole Result object. It extends SuiteVisitor that contains visiting logic for the test suite structure.

class robot.result.visitor.ResultVisitor[source]

Bases: SuiteVisitor

Abstract class to conveniently travel Result objects.

A visitor implementation can be given to the visit() method of a result object. This will cause the result object to be traversed and the visitor’s visit_x(), start_x(), and end_x() methods to be called for each suite, test, keyword and message, as well as for errors, statistics, and other information in the result object. See methods below for a full list of available visitor methods.

See the result package level documentation for more information about handling results and a concrete visitor example. For more information about the visitor algorithm see documentation in robot.model.visitor module.

visit_result(result)[source]
start_result(result)[source]
end_result(result)[source]
visit_statistics(stats)[source]
start_statistics(stats)[source]
end_statistics(stats)[source]
visit_total_statistics(stats)[source]
start_total_statistics(stats)[source]
end_total_statistics(stats)[source]
visit_tag_statistics(stats)[source]
start_tag_statistics(stats)[source]
end_tag_statistics(stats)[source]
visit_suite_statistics(stats)[source]
start_suite_statistics(stats)[source]
end_suite_statistics(suite_stats)[source]
visit_stat(stat)[source]
start_stat(stat)[source]
end_stat(stat)[source]
visit_errors(errors)[source]
start_errors(errors)[source]
end_errors(errors)[source]

robot.result.xmlelementhandlers module

class robot.result.xmlelementhandlers.XmlElementHandler(execution_result, root_handler=None)[source]

Bases: object

start(elem)[source]
end(elem)[source]
class robot.result.xmlelementhandlers.ElementHandler[source]

Bases: object

element_handlers = {'arg': <robot.result.xmlelementhandlers.ArgumentHandler object>, 'arguments': <robot.result.xmlelementhandlers.ArgumentsHandler object>, 'assign': <robot.result.xmlelementhandlers.AssignHandler object>, 'branch': <robot.result.xmlelementhandlers.BranchHandler object>, 'break': <robot.result.xmlelementhandlers.BreakHandler object>, 'continue': <robot.result.xmlelementhandlers.ContinueHandler object>, 'doc': <robot.result.xmlelementhandlers.DocHandler object>, 'error': <robot.result.xmlelementhandlers.ErrorHandler object>, 'errors': <robot.result.xmlelementhandlers.ErrorsHandler object>, 'for': <robot.result.xmlelementhandlers.ForHandler object>, 'if': <robot.result.xmlelementhandlers.IfHandler object>, 'item': <robot.result.xmlelementhandlers.MetadataItemHandler object>, 'iter': <robot.result.xmlelementhandlers.IterationHandler object>, 'kw': <robot.result.xmlelementhandlers.KeywordHandler object>, 'meta': <robot.result.xmlelementhandlers.MetaHandler object>, 'metadata': <robot.result.xmlelementhandlers.MetadataHandler object>, 'msg': <robot.result.xmlelementhandlers.MessageHandler object>, 'pattern': <robot.result.xmlelementhandlers.PatternHandler object>, 'return': <robot.result.xmlelementhandlers.ReturnHandler object>, 'robot': <robot.result.xmlelementhandlers.RobotHandler object>, 'statistics': <robot.result.xmlelementhandlers.StatisticsHandler object>, 'status': <robot.result.xmlelementhandlers.StatusHandler object>, 'suite': <robot.result.xmlelementhandlers.SuiteHandler object>, 'tag': <robot.result.xmlelementhandlers.TagHandler object>, 'tags': <robot.result.xmlelementhandlers.TagsHandler object>, 'test': <robot.result.xmlelementhandlers.TestHandler object>, 'timeout': <robot.result.xmlelementhandlers.TimeoutHandler object>, 'try': <robot.result.xmlelementhandlers.TryHandler object>, 'value': <robot.result.xmlelementhandlers.ValueHandler object>, 'var': <robot.result.xmlelementhandlers.VarHandler object>, 'variable': <robot.result.xmlelementhandlers.VariableHandler object>, 'while': <robot.result.xmlelementhandlers.WhileHandler object>}
tag = None
children = frozenset({})
classmethod register(handler)[source]
get_child_handler(tag)[source]
start(elem, result)[source]
end(elem, result)[source]
class robot.result.xmlelementhandlers.RootHandler[source]

Bases: ElementHandler

children = frozenset({'robot', 'suite'})
get_child_handler(tag)[source]
class robot.result.xmlelementhandlers.RobotHandler[source]

Bases: ElementHandler

tag = 'robot'
children = frozenset({'errors', 'statistics', 'suite'})
start(elem, result)[source]
class robot.result.xmlelementhandlers.SuiteHandler[source]

Bases: ElementHandler

tag = 'suite'
children = frozenset({'doc', 'kw', 'meta', 'metadata', 'status', 'suite', 'test'})
start(elem, result)[source]
get_child_handler(tag)[source]
class robot.result.xmlelementhandlers.TestHandler[source]

Bases: ElementHandler

tag = 'test'
children = frozenset({'break', 'continue', 'doc', 'error', 'for', 'if', 'kw', 'msg', 'return', 'status', 'tag', 'tags', 'timeout', 'try', 'variable', 'while'})
start(elem, result)[source]
class robot.result.xmlelementhandlers.KeywordHandler[source]

Bases: ElementHandler

tag = 'kw'
children = frozenset({'arg', 'arguments', 'assign', 'break', 'continue', 'doc', 'error', 'for', 'if', 'kw', 'msg', 'return', 'status', 'tag', 'tags', 'timeout', 'try', 'var', 'variable', 'while'})
start(elem, result)[source]
class robot.result.xmlelementhandlers.ForHandler[source]

Bases: ElementHandler

tag = 'for'
children = frozenset({'doc', 'iter', 'kw', 'msg', 'status', 'value', 'var'})
start(elem, result)[source]
class robot.result.xmlelementhandlers.WhileHandler[source]

Bases: ElementHandler

tag = 'while'
children = frozenset({'doc', 'iter', 'kw', 'msg', 'status'})
start(elem, result)[source]
class robot.result.xmlelementhandlers.IterationHandler[source]

Bases: ElementHandler

tag = 'iter'
children = frozenset({'break', 'continue', 'doc', 'error', 'for', 'if', 'kw', 'msg', 'return', 'status', 'try', 'var', 'variable', 'while'})
start(elem, result)[source]
class robot.result.xmlelementhandlers.IfHandler[source]

Bases: ElementHandler

tag = 'if'
children = frozenset({'branch', 'doc', 'kw', 'msg', 'status'})
start(elem, result)[source]
class robot.result.xmlelementhandlers.BranchHandler[source]

Bases: ElementHandler

tag = 'branch'
children = frozenset({'break', 'continue', 'doc', 'error', 'for', 'if', 'kw', 'msg', 'pattern', 'return', 'status', 'try', 'variable', 'while'})
start(elem, result)[source]
class robot.result.xmlelementhandlers.TryHandler[source]

Bases: ElementHandler

tag = 'try'
children = frozenset({'branch', 'doc', 'kw', 'msg', 'status'})
start(elem, result)[source]
class robot.result.xmlelementhandlers.PatternHandler[source]

Bases: ElementHandler

tag = 'pattern'
children = frozenset({})
end(elem, result)[source]
class robot.result.xmlelementhandlers.VariableHandler[source]

Bases: ElementHandler

tag = 'variable'
children = frozenset({'kw', 'msg', 'status', 'var'})
start(elem, result)[source]
class robot.result.xmlelementhandlers.ReturnHandler[source]

Bases: ElementHandler

tag = 'return'
children = frozenset({'kw', 'msg', 'status', 'value'})
start(elem, result)[source]
class robot.result.xmlelementhandlers.ContinueHandler[source]

Bases: ElementHandler

tag = 'continue'
children = frozenset({'kw', 'msg', 'status'})
start(elem, result)[source]
class robot.result.xmlelementhandlers.BreakHandler[source]

Bases: ElementHandler

tag = 'break'
children = frozenset({'kw', 'msg', 'status'})
start(elem, result)[source]
class robot.result.xmlelementhandlers.ErrorHandler[source]

Bases: ElementHandler

tag = 'error'
children = frozenset({'msg', 'status', 'value'})
start(elem, result)[source]
class robot.result.xmlelementhandlers.MessageHandler[source]

Bases: ElementHandler

tag = 'msg'
end(elem, result)[source]
class robot.result.xmlelementhandlers.ErrorMessageHandler[source]

Bases: MessageHandler

end(elem, result)[source]
class robot.result.xmlelementhandlers.StatusHandler(set_status=True)[source]

Bases: ElementHandler

tag = 'status'
end(elem, result)[source]
class robot.result.xmlelementhandlers.DocHandler[source]

Bases: ElementHandler

tag = 'doc'
end(elem, result)[source]
class robot.result.xmlelementhandlers.MetadataHandler[source]

Bases: ElementHandler

tag = 'metadata'
children = frozenset({'item'})
class robot.result.xmlelementhandlers.MetadataItemHandler[source]

Bases: ElementHandler

tag = 'item'
end(elem, result)[source]
class robot.result.xmlelementhandlers.MetaHandler[source]

Bases: ElementHandler

tag = 'meta'
end(elem, result)[source]
class robot.result.xmlelementhandlers.TagsHandler[source]

Bases: ElementHandler

tag = 'tags'
children = frozenset({'tag'})
class robot.result.xmlelementhandlers.TagHandler[source]

Bases: ElementHandler

tag = 'tag'
end(elem, result)[source]
class robot.result.xmlelementhandlers.TimeoutHandler[source]

Bases: ElementHandler

tag = 'timeout'
end(elem, result)[source]
class robot.result.xmlelementhandlers.AssignHandler[source]

Bases: ElementHandler

tag = 'assign'
children = frozenset({'var'})
class robot.result.xmlelementhandlers.VarHandler[source]

Bases: ElementHandler

tag = 'var'
end(elem, result)[source]
class robot.result.xmlelementhandlers.ArgumentsHandler[source]

Bases: ElementHandler

tag = 'arguments'
children = frozenset({'arg'})
class robot.result.xmlelementhandlers.ArgumentHandler[source]

Bases: ElementHandler

tag = 'arg'
end(elem, result)[source]
class robot.result.xmlelementhandlers.ValueHandler[source]

Bases: ElementHandler

tag = 'value'
end(elem, result)[source]
class robot.result.xmlelementhandlers.ErrorsHandler[source]

Bases: ElementHandler

tag = 'errors'
start(elem, result)[source]
get_child_handler(tag)[source]
class robot.result.xmlelementhandlers.StatisticsHandler[source]

Bases: ElementHandler

tag = 'statistics'
get_child_handler(tag)[source]