robot.running package
Implements the core test execution logic.
The public API of this module consists of the following objects:
TestSuite
for creating an executable test suite structure programmatically.TestSuiteBuilder
for creating executable test suites based on data on a file system. Instead of using this class directly, it is possible to use theTestSuite.from_file_system
classmethod that uses it internally.Classes used by
TestSuite
, such asTestCase
,Keyword
andIf
that are defined in therobot.running.model
module. These classes are typically only needed in type hints.Keyword implementation related classes
UserKeyword
,LibraryKeyword
,InvalidKeyword
and their common base classKeywordImplementation
. Also these classes are mainly needed in type hints.TestDefaults
that is part of the external parsing API and also typically needed only in type hints.
TestSuite
and
TestSuiteBuilder
can be imported also via
the robot.api
package.
Note
Prior to Robot Framework 6.1, only some classes in
robot.running.model
were exposed via robot.running
.
Keyword implementation related classes are new in Robot Framework 7.0.
Examples
First, let’s assume we have the following test suite in file
activate_skynet.robot
:
*** Settings ***
Library OperatingSystem
*** Test Cases ***
Should Activate Skynet
[Tags] smoke
[Setup] Set Environment Variable SKYNET activated
Environment Variable Should Be Set SKYNET
We can easily create an executable test suite based on the above file:
from robot.api import TestSuite
suite = TestSuite.from_file_system('path/to/activate_skynet.robot')
That was easy. Let’s next generate the same test suite from scratch:
from robot.api import TestSuite
suite = TestSuite('Activate Skynet')
suite.resource.imports.library('OperatingSystem')
test = suite.tests.create('Should Activate Skynet', tags=['smoke'])
test.setup.config(name='Set Environment Variable', args=['SKYNET', 'activated'])
test.body.create_keyword('Environment Variable Should Be Set', args=['SKYNET'])
Not that complicated either, especially considering the flexibility. Notice that the suite created based on the file could also be edited further using the same API.
Now that we have a test suite ready, let’s execute it
and verify that the returned
Result
object contains correct
information:
result = suite.run(output='skynet.xml')
assert result.return_code == 0
assert result.suite.name == 'Activate Skynet'
test = result.suite.tests[0]
assert test.name == 'Should Activate Skynet'
assert test.passed
stats = result.suite.statistics
assert stats.total == 1 and stats.passed == 1 and stats.failed == 0
Running the suite generates a normal output XML file, unless it is disabled
by using output=None
. Generating log, report, and xUnit files based on
the results is possible using the
ResultWriter
class:
from robot.api import ResultWriter
# Report and xUnit files can be generated based on the result object.
ResultWriter(result).write_results(report='skynet.html', log=None)
# Generating log files requires processing the earlier generated output XML.
ResultWriter('skynet.xml').write_results()
Subpackages
- robot.running.arguments package
- Submodules
- robot.running.arguments.argumentconverter module
- robot.running.arguments.argumentmapper module
- robot.running.arguments.argumentparser module
- robot.running.arguments.argumentresolver module
- robot.running.arguments.argumentspec module
- robot.running.arguments.argumentvalidator module
- robot.running.arguments.customconverters module
- robot.running.arguments.embedded module
- robot.running.arguments.typeconverters module
- robot.running.arguments.typeinfo module
- robot.running.arguments.typeinfoparser module
- robot.running.arguments.typevalidator module
- robot.running.builder package
- robot.running.timeouts package
Submodules
robot.running.bodyrunner module
- class robot.running.bodyrunner.BodyRunner(context, run=True, templated=False)[source]
Bases:
object
- class robot.running.bodyrunner.ForInRunner(context, run=True, templated=False)[source]
Bases:
object
- flavor = 'IN'
- class robot.running.bodyrunner.ForInRangeRunner(context, run=True, templated=False)[source]
Bases:
ForInRunner
- flavor = 'IN RANGE'
- class robot.running.bodyrunner.ForInZipRunner(context, run=True, templated=False)[source]
Bases:
ForInRunner
- flavor = 'IN ZIP'
- class robot.running.bodyrunner.ForInEnumerateRunner(context, run=True, templated=False)[source]
Bases:
ForInRunner
- flavor = 'IN ENUMERATE'
- class robot.running.bodyrunner.WhileRunner(context, run=True, templated=False)[source]
Bases:
object
- class robot.running.bodyrunner.WhileLimit(on_limit=None, on_limit_message=None)[source]
Bases:
object
- class robot.running.bodyrunner.DurationLimit(max_time, on_limit, on_limit_message)[source]
Bases:
WhileLimit
- class robot.running.bodyrunner.IterationCountLimit(max_iterations, on_limit, on_limit_message)[source]
Bases:
WhileLimit
- class robot.running.bodyrunner.NoLimit(on_limit=None, on_limit_message=None)[source]
Bases:
WhileLimit
- exception robot.running.bodyrunner.LimitExceeded(on_limit_pass, message)[source]
Bases:
ExecutionFailed
robot.running.context module
robot.running.dynamicmethods module
- class robot.running.dynamicmethods.GetKeywordNames(instance)[source]
Bases:
DynamicMethod
- class robot.running.dynamicmethods.RunKeyword(instance, keyword_name: str | None = None, supports_named_args: bool | None = None)[source]
Bases:
DynamicMethod
- property supports_named_args: bool
- class robot.running.dynamicmethods.GetKeywordDocumentation(instance)[source]
Bases:
DynamicMethod
- class robot.running.dynamicmethods.GetKeywordArguments(instance, supports_named_args: bool | None = None)[source]
Bases:
DynamicMethod
- class robot.running.dynamicmethods.GetKeywordTypes(instance)[source]
Bases:
DynamicMethod
- class robot.running.dynamicmethods.GetKeywordTags(instance)[source]
Bases:
DynamicMethod
- class robot.running.dynamicmethods.GetKeywordSource(instance)[source]
Bases:
DynamicMethod
robot.running.importer module
robot.running.invalidkeyword module
- class robot.running.invalidkeyword.InvalidKeyword(name: str = '', args: ArgumentSpec | None = None, doc: str = '', tags: Tags | Sequence[str] = (), lineno: int | None = None, owner: ResourceFile | TestLibrary | None = None, parent: BodyItemParent | None = None, error: str | None = None)[source]
Bases:
KeywordImplementation
Represents an invalid keyword call.
Keyword may not have been found, there could have been multiple matches, or the keyword call itself could have been invalid.
- type: Literal['USER KEYWORD', 'LIBRARY KEYWORD', 'INVALID KEYWORD'] = 'INVALID KEYWORD'
- bind(data: Keyword) InvalidKeyword [source]
- embedded
- owner
- parent
- error
robot.running.keywordfinder module
- class robot.running.keywordfinder.KeywordFinder(owner: TestLibrary | ResourceFile)[source]
Bases:
Generic
[K
]- find(name: str, count: Literal[1]) K [source]
- find(name: str, count: int | None = None) list[K]
Find keywords based on the given
name
.With normal keywords matching is a case, space and underscore insensitive string comparison and there cannot be more than one match. With keywords accepting embedded arguments, matching is done against the name and there can be multiple matches.
Returns matching keywords as a list, possibly as an empty list, without any validation by default. If the optional
count
is used, raises aValueError
if the number of found keywords does not match. Ifcount
is1
and exactly one keyword is found, returns that keyword directly and not as a list.
robot.running.keywordimplementation module
- class robot.running.keywordimplementation.KeywordImplementation(name: str = '', args: ArgumentSpec | None = None, doc: str = '', tags: Tags | Sequence[str] = (), lineno: int | None = None, owner: ResourceFile | TestLibrary | None = None, parent: BodyItemParent | None = None, error: str | None = None)[source]
Bases:
ModelObject
Base class for different keyword implementations.
- USER_KEYWORD = 'USER KEYWORD'
- LIBRARY_KEYWORD = 'LIBRARY KEYWORD'
- INVALID_KEYWORD = 'INVALID KEYWORD'
- repr_args = ('name', 'args')
- type: Literal['USER KEYWORD', 'LIBRARY KEYWORD', 'INVALID KEYWORD']
- embedded
- owner
- parent
- error
- property name: str
- property full_name: str
- args
Information about accepted arguments.
It would be more correct to use term parameter instead of argument in this context, and this attribute may be renamed accordingly in the future. A forward compatible
params
attribute exists already now.
- property params: ArgumentSpec
Keyword parameter information.
This is a forward compatible alias for
args
.
- property doc: str
- property short_doc: str
- tags
- property lineno: int | None
- property private: bool
- property source: Path | None
- matches(name: str) bool [source]
Returns true if
name
matches the keyword name.With normal keywords matching is a case, space and underscore insensitive string comparison. With keywords accepting embedded arguments, matching is done against the name.
- resolve_arguments(args: Sequence[str | Any], named_args: Mapping[str, Any] | None = None, variables=None, languages: LanguagesLike = None) tuple[list, list] [source]
- create_runner(name: str | None, languages: LanguagesLike = None) LibraryKeywordRunner | UserKeywordRunner [source]
- bind(data: Keyword) KeywordImplementation [source]
robot.running.librarykeyword module
- class robot.running.librarykeyword.LibraryKeyword(owner: TestLibrary, name: str = '', args: ArgumentSpec | None = None, doc: str = '', tags: Tags | Sequence[str] = (), resolve_args_until: int | None = None, parent: BodyItemParent | None = None, error: str | None = None)[source]
Bases:
KeywordImplementation
Base class for different library keywords.
- type: Literal['USER KEYWORD', 'LIBRARY KEYWORD', 'INVALID KEYWORD'] = 'LIBRARY KEYWORD'
- property method: Callable[[...], Any]
- property lineno: int | None
- create_runner(name: str | None, languages: LanguagesLike = None) LibraryKeywordRunner [source]
- resolve_arguments(args: Sequence[str | Any], named_args: Mapping[str, Any] | None = None, variables=None, languages: LanguagesLike = None) tuple[list, list] [source]
- copy(**attributes) Self [source]
Return a shallow copy of this object.
- Parameters:
attributes – Attributes to be set to the returned copy. For example,
obj.copy(name='New name')
.
See also
deepcopy()
. The difference betweencopy
anddeepcopy
is the same as with the methods having same names in the copy module.
- class robot.running.librarykeyword.StaticKeyword(method_name: str, owner: TestLibrary, name: str = '', args: ArgumentSpec | None = None, doc: str = '', tags: Tags | Sequence[str] = (), resolve_args_until: int | None = None, parent: BodyItemParent | None = None, error: str | None = None)[source]
Bases:
LibraryKeyword
Represents a keyword in a static library.
- method_name
- property method: Callable[[...], Any]
Keyword method.
- property source: Path | None
- classmethod from_name(name: str, owner: TestLibrary) StaticKeyword [source]
- copy(**attributes) StaticKeyword [source]
Return a shallow copy of this object.
- Parameters:
attributes – Attributes to be set to the returned copy. For example,
obj.copy(name='New name')
.
See also
deepcopy()
. The difference betweencopy
anddeepcopy
is the same as with the methods having same names in the copy module.
- class robot.running.librarykeyword.DynamicKeyword(owner: DynamicLibrary, name: str = '', args: ArgumentSpec | None = None, doc: str = '', tags: Tags | Sequence[str] = (), resolve_args_until: int | None = None, parent: BodyItemParent | None = None, error: str | None = None)[source]
Bases:
LibraryKeyword
Represents a keyword in a dynamic library.
- property method: Callable[[...], Any]
Dynamic
run_keyword
method.
- property source: Path | None
- property lineno: int | None
- classmethod from_name(name: str, owner: DynamicLibrary) DynamicKeyword [source]
- resolve_arguments(args: Sequence[str | Any], named_args: Mapping[str, Any] | None = None, variables=None, languages: LanguagesLike = None) tuple[list, list] [source]
- copy(**attributes) DynamicKeyword [source]
Return a shallow copy of this object.
- Parameters:
attributes – Attributes to be set to the returned copy. For example,
obj.copy(name='New name')
.
See also
deepcopy()
. The difference betweencopy
anddeepcopy
is the same as with the methods having same names in the copy module.
- run_keyword
- class robot.running.librarykeyword.LibraryInit(owner: TestLibrary, name: str = '', args: ArgumentSpec | None = None, doc: str = '', tags: Tags | Sequence[str] = (), positional: list | None = None, named: dict | None = None)[source]
Bases:
LibraryKeyword
Represents a library initializer.
positional
andnamed
contain arguments used for initializing the library.- property doc: str
- property method: Callable[[...], None] | None
Initializer method.
None
with module based libraries and when class based libraries do not have__init__
.
- classmethod from_class(klass) LibraryInit [source]
- classmethod null() LibraryInit [source]
- copy(**attributes) LibraryInit [source]
Return a shallow copy of this object.
- Parameters:
attributes – Attributes to be set to the returned copy. For example,
obj.copy(name='New name')
.
See also
deepcopy()
. The difference betweencopy
anddeepcopy
is the same as with the methods having same names in the copy module.
- class robot.running.librarykeyword.KeywordCreator(name: str, library: TestLibrary | None = None)[source]
Bases:
Generic
[K
]- keyword_class: type[K]
- property instance: Any
- get_args() ArgumentSpec [source]
- class robot.running.librarykeyword.StaticKeywordCreator(name: str, library: TestLibrary)[source]
Bases:
KeywordCreator
[StaticKeyword
]- keyword_class
alias of
StaticKeyword
- get_args() ArgumentSpec [source]
- class robot.running.librarykeyword.DynamicKeywordCreator(name: str, library: TestLibrary | None = None)[source]
Bases:
KeywordCreator
[DynamicKeyword
]- keyword_class
alias of
DynamicKeyword
- library: DynamicLibrary
- get_args() ArgumentSpec [source]
- class robot.running.librarykeyword.LibraryInitCreator(method: Callable[[...], None] | None)[source]
Bases:
KeywordCreator
[LibraryInit
]- keyword_class
alias of
LibraryInit
- create(**extra) LibraryInit [source]
- get_args() ArgumentSpec [source]
robot.running.librarykeywordrunner module
- class robot.running.librarykeywordrunner.LibraryKeywordRunner(keyword: LibraryKeyword, name: str | None = None, languages=None)[source]
Bases:
object
- class robot.running.librarykeywordrunner.EmbeddedArgumentsRunner(keyword: LibraryKeyword, name: str)[source]
Bases:
LibraryKeywordRunner
- class robot.running.librarykeywordrunner.RunKeywordRunner(keyword: LibraryKeyword, execute_in_dry_run=False)[source]
Bases:
LibraryKeywordRunner
robot.running.libraryscopes module
- class robot.running.libraryscopes.Scope(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
Enum
- GLOBAL = 1
- SUITE = 2
- TEST = 3
- class robot.running.libraryscopes.ScopeManager(library: TestLibrary)[source]
Bases:
object
- class robot.running.libraryscopes.GlobalScopeManager(library: TestLibrary)[source]
Bases:
ScopeManager
- class robot.running.libraryscopes.SuiteScopeManager(library)[source]
Bases:
ScopeManager
robot.running.model module
Module implementing test execution related model objects.
When tests are executed by Robot Framework, a TestSuite
structure using
classes defined in this module is created by
TestSuiteBuilder
based on data on a file system. In addition to that, external tools can
create executable suite structures programmatically.
Regardless the approach to construct it, a TestSuite
object is executed
by calling its run()
method as shown in the example in
the robot.running
package level documentation. When a suite is run,
test, keywords, and other objects it contains can be inspected and modified
by using pre-run modifiers and listeners.
The TestSuite
class is exposed via the robot.api
package. If other
classes are needed, they can be imported from robot.running
.
- class robot.running.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, model.Message, Error]
- class robot.running.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, model.Message, Error,IT
]
- class robot.running.model.Argument(name: str | None, value: Any)[source]
Bases:
object
A temporary API for creating named arguments with non-string values.
This class was added in RF 7.0.1 (#5031) after a failed attempt to add a public API for this purpose in RF 7.0 (#5000). A better public API that allows passing named arguments separately was added in RF 7.1 (#5143).
If you need to support also RF 7.0, you can pass named arguments as two-item tuples like (name, value) and positional arguments as one-item tuples like (value,). That approach does not work anymore in RF 7.0.1, though, so the code needs to be conditional depending on Robot Framework version.
The main limitation of this class is that it is not compatible with the JSON model. The current plan is to remove this in the future, possibly already in RF 8.0, but we can consider preserving it if it turns out to be useful.
- Parameters:
name – Argument name. If
None
, argument is considered positional.value – Argument value.
- class robot.running.model.Keyword(name: str = '', args: Sequence[str | Argument | Any] = (), named_args: Mapping[str, Any] | None = None, assign: Sequence[str] = (), type: str = 'KEYWORD', parent: TestSuite | TestCase | UserKeyword | For | If | IfBranch | Try | TryBranch | While | None = None, lineno: int | None = None)[source]
Bases:
Keyword
,WithSource
Represents an executable keyword call.
A keyword call consists only of a keyword name, arguments and possible assignment in the data:
Keyword arg ${result} = Another Keyword arg1 arg2
The actual keyword that is executed depends on the context where this model is executed.
Arguments originating from normal Robot Framework data are stored in the
args
attribute as a tuple of strings in the exact same format as in the data. This means that arguments can have variables and escape characters, and that named arguments are specified using thename=value
syntax.When creating keywords programmatically, it is possible to set
named_args
separately and useargs
only for positional arguments. Argument values do not need to be strings, but also in this case strings can contain variables and normal Robot Framework escaping rules must be taken into account.- named_args
- lineno
- class robot.running.model.ForIteration(assign: Mapping[str, str] | None = None, parent: TestSuite | TestCase | UserKeyword | For | If | IfBranch | Try | TryBranch | While | None = None, lineno: int | None = None, error: str | None = None)[source]
Bases:
ForIteration
,WithSource
- lineno
- error
- class robot.running.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, parent: TestSuite | TestCase | UserKeyword | For | If | IfBranch | Try | TryBranch | While | None = None, lineno: int | None = None, error: str | None = None)[source]
Bases:
For
,WithSource
- lineno
- error
- classmethod from_dict(data: Dict[str, Any]) For [source]
Create this object based on data in a dictionary.
Data can be got from the
to_dict()
method or created externally.With
robot.running
model objects new in Robot Framework 6.1, withrobot.result
new in Robot Framework 7.0.
- 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, withrobot.result
new in Robot Framework 7.0.
- get_iteration(assign: Mapping[str, str] | None = None) ForIteration [source]
- class robot.running.model.WhileIteration(parent: TestSuite | TestCase | UserKeyword | For | If | IfBranch | Try | TryBranch | While | None = None, lineno: int | None = None, error: str | None = None)[source]
Bases:
WhileIteration
,WithSource
- lineno
- error
- class robot.running.model.While(condition: str | None = None, limit: str | None = None, on_limit: str | None = None, on_limit_message: str | None = None, parent: TestSuite | TestCase | UserKeyword | For | If | IfBranch | Try | TryBranch | While | None = None, lineno: int | None = None, error: str | None = None)[source]
Bases:
While
,WithSource
- lineno
- 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, withrobot.result
new in Robot Framework 7.0.
- get_iteration() WhileIteration [source]
- class robot.running.model.IfBranch(type: str = 'IF', condition: str | None = None, parent: TestSuite | TestCase | UserKeyword | For | If | IfBranch | Try | TryBranch | While | None = None, lineno: int | None = None)[source]
Bases:
IfBranch
,WithSource
- lineno
- class robot.running.model.If(parent: TestSuite | TestCase | UserKeyword | For | If | IfBranch | Try | TryBranch | While | None = None, lineno: int | None = None, error: str | None = None)[source]
Bases:
If
,WithSource
- lineno
- error
- class robot.running.model.TryBranch(type: str = 'TRY', patterns: Sequence[str] = (), pattern_type: str | None = None, assign: str | None = None, parent: TestSuite | TestCase | UserKeyword | For | If | IfBranch | Try | TryBranch | While | None = None, lineno: int | None = None)[source]
Bases:
TryBranch
,WithSource
- lineno
- classmethod from_dict(data: Dict[str, Any]) TryBranch [source]
Create this object based on data in a dictionary.
Data can be got from the
to_dict()
method or created externally.With
robot.running
model objects new in Robot Framework 6.1, withrobot.result
new in Robot Framework 7.0.
- 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, withrobot.result
new in Robot Framework 7.0.
- class robot.running.model.Try(parent: TestSuite | TestCase | UserKeyword | For | If | IfBranch | Try | TryBranch | While | None = None, lineno: int | None = None, error: str | None = None)[source]
Bases:
Try
,WithSource
- lineno
- error
- class robot.running.model.Var(name: str = '', value: str | Sequence[str] = (), scope: str | None = None, separator: str | None = None, parent: TestSuite | TestCase | UserKeyword | For | If | IfBranch | Try | TryBranch | While | None = None, lineno: int | None = None, error: str | None = None)[source]
Bases:
Var
,WithSource
- lineno
- error
- class robot.running.model.Return(values: Sequence[str] = (), parent: TestSuite | TestCase | UserKeyword | For | If | IfBranch | Try | TryBranch | While | None = None, lineno: int | None = None, error: str | None = None)[source]
Bases:
Return
,WithSource
- lineno
- error
- class robot.running.model.Continue(parent: TestSuite | TestCase | UserKeyword | For | If | IfBranch | Try | TryBranch | While | None = None, lineno: int | None = None, error: str | None = None)[source]
Bases:
Continue
,WithSource
- lineno
- error
- class robot.running.model.Break(parent: TestSuite | TestCase | UserKeyword | For | If | IfBranch | Try | TryBranch | While | None = None, lineno: int | None = None, error: str | None = None)[source]
Bases:
Break
,WithSource
- lineno
- error
- class robot.running.model.Error(values: Sequence[str] = (), parent: TestSuite | TestCase | UserKeyword | For | If | IfBranch | Try | TryBranch | While | None = None, lineno: int | None = None, error: str = '')[source]
Bases:
Error
,WithSource
- lineno
- error
- class robot.running.model.TestCase(name: str = '', doc: str = '', tags: Sequence[str] = (), timeout: str | None = None, lineno: int | None = None, parent: TestSuite | None = None, template: str | None = None, error: str | None = None)[source]
-
Represents a single executable test case.
See the base class for documentation of attributes not documented here.
- template
- 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, withrobot.result
new in Robot Framework 7.0.
- body
Test body as a
Body
object.
- class robot.running.model.TestSuite(name: str = '', doc: str = '', metadata: Mapping[str, str] | None = None, source: Path | str | None = None, rpa: bool | None = False, parent: TestSuite | None = None)[source]
Bases:
TestSuite
[Keyword
,TestCase
]Represents a single executable test suite.
See the base class for documentation of attributes not documented here.
- resource
ResourceFile
instance containing imports, variables and keywords the suite owns. When data is parsed from the file system, this data comes from the same test case file that creates the suite.
- classmethod from_file_system(*paths: Path | str, **config) TestSuite [source]
Create a
TestSuite
object based on the givenpaths
.- Parameters:
paths – File or directory paths where to read the data from.
config – Configuration parameters for
TestSuiteBuilder
class that is used internally for building the suite.
See also
from_model()
andfrom_string()
.
- classmethod from_model(model: File, name: str | None = None, *, defaults: TestDefaults | None = None) TestSuite [source]
Create a
TestSuite
object based on the givenmodel
.- Parameters:
model – Model to create the suite from.
name – Deprecated since Robot Framework 6.1.
defaults – Possible test specific defaults from suite initialization files. New in Robot Framework 6.1.
The model can be created by using the
get_model()
function and possibly modified by other tooling in therobot.parsing
module.Giving suite name is deprecated and users should set it and possible other attributes to the returned suite separately. One easy way is using the
config()
method like this:suite = TestSuite.from_model(model).config(name='X', doc='Example')
See also
from_file_system()
andfrom_string()
.
- classmethod from_string(string: str, *, defaults: TestDefaults | None = None, **config) TestSuite [source]
Create a
TestSuite
object based on the givenstring
.- Parameters:
string – String to create the suite from.
defaults – Possible test specific defaults from suite initialization files.
config – Configuration parameters for
get_model()
used internally.
If suite name or other attributes need to be set, an easy way is using the
config()
method like this:suite = TestSuite.from_string(string).config(name='X', doc='Example')
New in Robot Framework 6.1. See also
from_model()
andfrom_file_system()
.
- configure(randomize_suites: bool = False, randomize_tests: bool = False, randomize_seed: int | None = None, **options)[source]
A shortcut to configure a suite using one method call.
Can only be used with the root test suite.
- Parameters:
randomize_xxx – Passed to
randomize()
.options – Passed to
SuiteConfigurer
that will then set suite attributes, callfilter()
, etc. as needed.
Example:
suite.configure(include_tags=['smoke'], 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.
- randomize(suites: bool = True, tests: bool = True, seed: int | None = None)[source]
Randomizes the order of suites and/or tests, recursively.
- Parameters:
suites – Boolean controlling should suites be randomized.
tests – Boolean controlling should tests be randomized.
seed – Random seed. Can be given if previous random order needs to be re-created. Seed value is always shown in logs and reports.
- suites
- run(settings=None, **options)[source]
Executes the suite based on the given
settings
oroptions
.- Parameters:
settings –
RobotSettings
object to configure test execution.options – Used to construct new
RobotSettings
object ifsettings
are not given.
- Returns:
Result
object with information about executed suites and tests.
If
options
are used, their names are the same as long command line options except without hyphens. Some options are ignored (see below), but otherwise they have the same semantics as on the command line. Options that can be given on the command line multiple times can be passed as lists likevariable=['VAR1:value1', 'VAR2:value2']
. If such an option is used only once, it can be given also as a single string likevariable='VAR:value'
.Additionally, listener option allows passing object directly instead of listener name, e.g.
run('tests.robot', listener=Listener())
.To capture stdout and/or stderr streams, pass open file objects in as special keyword arguments
stdout
andstderr
, respectively.Only options related to the actual test execution have an effect. For example, options related to selecting or modifying test cases or suites (e.g.
--include
,--name
,--prerunmodifier
) or creating logs and reports are silently ignored. The output XML generated as part of the execution can be configured, though. This includes disabling it withoutput=None
.Example:
stdout = StringIO() result = suite.run(variable='EXAMPLE:value', output='example.xml', exitonfailure=True, stdout=stdout) print(result.return_code)
To save memory, the returned
Result
object does not have any information about the executed keywords. If that information is needed, the created output XML file needs to be read using theExecutionResult
factory method.See the
package level
documentation for more examples, including how to construct executable test suites and how to create logs and reports based on the execution results.See the
robot.run
function for a higher-level API for executing tests in files or directories.
robot.running.namespace module
- class robot.running.namespace.Namespace(variables, suite, resource, languages)[source]
Bases:
object
- property libraries
robot.running.outputcapture module
robot.running.randomizer module
- class robot.running.randomizer.Randomizer(randomize_suites=True, randomize_tests=True, seed=None)[source]
Bases:
SuiteVisitor
- start_suite(suite)[source]
Called when a suite starts. Default implementation does nothing.
Can return explicit
False
to stop visiting.
robot.running.resourcemodel module
- class robot.running.resourcemodel.ResourceFile(source: Path | str | None = None, owner: TestSuite | None = None, doc: str = '')[source]
Bases:
ModelObject
Represents a resource file.
- repr_args = ('source',)
- owner
- doc
- keyword_finder
- property source: Path | None
- property name: str | None
Resource file name.
None
if resource file is part of a suite or if it does not havesource
, name of the source file without the extension otherwise.
- imports
- variables
- keywords
- classmethod from_file_system(path: Path | str, **config) ResourceFile [source]
Create a
ResourceFile
object based on the givepath
.- Parameters:
path – File path where to read the data from.
config – Configuration parameters for
ResourceFileBuilder
class that is used internally for building the suite.
New in Robot Framework 6.1. See also
from_string()
andfrom_model()
.
- classmethod from_string(string: str, **config) ResourceFile [source]
Create a
ResourceFile
object based on the givenstring
.- Parameters:
string – String to create the resource file from.
config – Configuration parameters for
get_resource_model()
used internally.
New in Robot Framework 6.1. See also
from_file_system()
andfrom_model()
.
- classmethod from_model(model: File) ResourceFile [source]
Create a
ResourceFile
object based on the givenmodel
.- Parameters:
model – Model to create the suite from.
The model can be created by using the
get_resource_model()
function and possibly modified by other tooling in therobot.parsing
module.New in Robot Framework 6.1. See also
from_file_system()
andfrom_string()
.
- find_keywords(name: str, count: Literal[1]) UserKeyword [source]
- find_keywords(name: str, count: int | None = None) list[UserKeyword]
- class robot.running.resourcemodel.UserKeyword(name: str = '', args: ArgumentSpec | Sequence[str] | None = (), doc: str = '', tags: Tags | Sequence[str] = (), timeout: str | None = None, lineno: int | None = None, owner: ResourceFile | None = None, parent: BodyItemParent | None = None, error: str | None = None)[source]
Bases:
KeywordImplementation
Represents a user keyword.
- type: Literal['USER KEYWORD', 'LIBRARY KEYWORD', 'INVALID KEYWORD'] = 'USER KEYWORD'
- timeout
- args
- body
- 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 has_teardown: bool
Check does a keyword have a teardown without creating a teardown object.
A difference between using
if kw.has_teardown:
andif kw.teardown:
is that accessing theteardown
attribute creates aKeyword
object representing the teardown even when the user keyword actually does not have one. This can have an effect on memory usage.New in Robot Framework 6.1.
- create_runner(name: str | None, languages: LanguagesLike = None) UserKeywordRunner | EmbeddedArgumentsRunner [source]
- bind(data: Keyword) UserKeyword [source]
- class robot.running.resourcemodel.Variable(name: str = '', value: Sequence[str] = (), separator: str | None = None, owner: ResourceFile | None = None, lineno: int | None = None, error: str | None = None)[source]
Bases:
ModelObject
- repr_args = ('name', 'value', 'separator')
- property source: Path | None
- class robot.running.resourcemodel.Import(type: Literal['LIBRARY', 'RESOURCE', 'VARIABLES'], name: str, args: Sequence[str] = (), alias: str | None = None, owner: ResourceFile | None = None, lineno: int | None = None)[source]
Bases:
ModelObject
Represents library, resource file or variable file import.
- repr_args = ('type', 'name', 'args', 'alias')
- LIBRARY = 'LIBRARY'
- RESOURCE = 'RESOURCE'
- VARIABLES = 'VARIABLES'
- property source: Path | None
- property directory: Path | None
- property setting_name: str
- classmethod from_dict(data) Import [source]
Create this object based on data in a dictionary.
Data can be got from the
to_dict()
method or created externally.With
robot.running
model objects new in Robot Framework 6.1, withrobot.result
new in Robot Framework 7.0.
- 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, withrobot.result
new in Robot Framework 7.0.
- class robot.running.resourcemodel.Imports(owner: ResourceFile, imports: Sequence[Import] = ())[source]
Bases:
ItemList
- library(name: str, args: Sequence[str] = (), alias: str | None = None, lineno: int | None = None) Import [source]
Create library import.
- variables(name: str, args: Sequence[str] = (), lineno: int | None = None) Import [source]
Create variables import.
- create(*args, **kwargs) Import [source]
Generic method for creating imports.
Import type specific methods
library()
,resource()
andvariables()
are recommended over this method.
- class robot.running.resourcemodel.Variables(owner: ResourceFile, variables: Sequence[Variable] = ())[source]
- class robot.running.resourcemodel.UserKeywords(owner: ResourceFile, keywords: Sequence[UserKeyword] = ())[source]
Bases:
ItemList
[UserKeyword
]- append(item: UserKeyword | Dict[str, Any]) UserKeyword [source]
S.append(value) – append value to the end of the sequence
- extend(items: Iterable[UserKeyword | Dict[str, Any]])[source]
S.extend(iterable) – extend sequence by appending elements from the iterable
- insert(index: int, item: UserKeyword | Dict[str, Any])[source]
S.insert(index, value) – insert value before index
robot.running.runkwregister module
robot.running.signalhandler module
robot.running.status module
- class robot.running.status.Exit(failure_mode=False, error_mode=False, skip_teardown_mode=False)[source]
Bases:
object
- property teardown_allowed
- class robot.running.status.SuiteStatus(parent=None, exit_on_failure=False, exit_on_error=False, skip_teardown_on_exit=False)[source]
Bases:
_ExecutionStatus
- class robot.running.status.TestStatus(parent, test, skip_on_failure=None, rpa=False)[source]
Bases:
_ExecutionStatus
- property skip_on_failure_after_tag_changes
- class robot.running.status.TestMessage(status)[source]
Bases:
_Message
- setup_message = 'Setup failed:\n%s'
- teardown_message = 'Teardown failed:\n%s'
- setup_skipped_message = '%s'
- teardown_skipped_message = '%s'
- also_teardown_message = '%s\n\nAlso teardown failed:\n%s'
- also_teardown_skip_message = 'Skipped in teardown:\n%s\n\nEarlier message:\n%s'
- exit_on_fatal_message = 'Test execution stopped due to a fatal error.'
- exit_on_failure_message = 'Failure occurred and exit-on-failure mode is in use.'
- exit_on_error_message = 'Error occurred and exit-on-error mode is in use.'
- property message
- class robot.running.status.SuiteMessage(status)[source]
Bases:
_Message
- setup_message = 'Suite setup failed:\n%s'
- setup_skipped_message = 'Skipped in suite setup:\n%s'
- teardown_skipped_message = 'Skipped in suite teardown:\n%s'
- teardown_message = 'Suite teardown failed:\n%s'
- also_teardown_message = '%s\n\nAlso suite teardown failed:\n%s'
- also_teardown_skip_message = 'Skipped in suite teardown:\n%s\n\nEarlier message:\n%s'
- class robot.running.status.ParentMessage(status)[source]
Bases:
SuiteMessage
- setup_message = 'Parent suite setup failed:\n%s'
- setup_skipped_message = 'Skipped in parent suite setup:\n%s'
- teardown_skipped_message = 'Skipped in parent suite teardown:\n%s'
- teardown_message = 'Parent suite teardown failed:\n%s'
- also_teardown_message = '%s\n\nAlso parent suite teardown failed:\n%s'
robot.running.statusreporter module
robot.running.suiterunner module
robot.running.testlibraries module
- class robot.running.testlibraries.TestLibrary(code: type | ~types.ModuleType, init: ~robot.running.librarykeyword.LibraryInit, name: str | None = None, real_name: str | None = None, source: ~pathlib.Path | None = None, logger=<robot.output.logger.Logger object>)[source]
Bases:
object
Represents imported test library.
- property instance: Any
Current library instance.
With module based libraries this is the module itself.
With class based libraries this is an instance of the class. Instances are cleared automatically during execution based on their scope. Accessing this property creates a new instance if needed.
code´ contains the original library code. With module based libraries it is the same as :attr:`instance
. With class based libraries it is the library class.
- property listeners: list[Any]
- property converters: CustomArgumentConverters | None
- property doc: str
- property doc_format: str
- source
- property version: str
- property lineno: int
- classmethod from_name(name: str, real_name: str | None = None, args: ~typing.Sequence[str] | None = None, variables=None, create_keywords: bool = True, logger=<robot.output.logger.Logger object>) TestLibrary [source]
- classmethod from_code(code: type | ~types.ModuleType, name: str | None = None, real_name: str | None = None, source: ~pathlib.Path | None = None, args: ~typing.Sequence[str] | None = None, variables=None, create_keywords: bool = True, logger=<robot.output.logger.Logger object>) TestLibrary [source]
- classmethod from_module(module: ~types.ModuleType, name: str | None = None, real_name: str | None = None, source: ~pathlib.Path | None = None, create_keywords: bool = True, logger=<robot.output.logger.Logger object>) TestLibrary [source]
- classmethod from_class(klass: type, name: str | None = None, real_name: str | None = None, source: ~pathlib.Path | None = None, args: ~typing.Sequence[str] = (), variables=None, create_keywords: bool = True, logger=<robot.output.logger.Logger object>) TestLibrary [source]
- find_keywords(name: str, count: Literal[1]) LibraryKeyword [source]
- find_keywords(name: str, count: int | None = None) list[LibraryKeyword]
- class robot.running.testlibraries.ModuleLibrary(code: type | ~types.ModuleType, init: ~robot.running.librarykeyword.LibraryInit, name: str | None = None, real_name: str | None = None, source: ~pathlib.Path | None = None, logger=<robot.output.logger.Logger object>)[source]
Bases:
TestLibrary
- classmethod from_module(module: ~types.ModuleType, name: str | None = None, real_name: str | None = None, source: ~pathlib.Path | None = None, create_keywords: bool = True, logger=<robot.output.logger.Logger object>) ModuleLibrary [source]
- classmethod from_class(*args, **kws) TestLibrary [source]
- class robot.running.testlibraries.ClassLibrary(code: type | ~types.ModuleType, init: ~robot.running.librarykeyword.LibraryInit, name: str | None = None, real_name: str | None = None, source: ~pathlib.Path | None = None, logger=<robot.output.logger.Logger object>)[source]
Bases:
TestLibrary
- property instance: Any
Current library instance.
With module based libraries this is the module itself.
With class based libraries this is an instance of the class. Instances are cleared automatically during execution based on their scope. Accessing this property creates a new instance if needed.
code´ contains the original library code. With module based libraries it is the same as :attr:`instance
. With class based libraries it is the library class.
- property lineno: int
- classmethod from_module(*args, **kws) TestLibrary [source]
- classmethod from_class(klass: type, name: str | None = None, real_name: str | None = None, source: ~pathlib.Path | None = None, args: ~typing.Sequence[str] = (), variables=None, create_keywords: bool = True, logger=<robot.output.logger.Logger object>) ClassLibrary [source]
- class robot.running.testlibraries.HybridLibrary(code: type | ~types.ModuleType, init: ~robot.running.librarykeyword.LibraryInit, name: str | None = None, real_name: str | None = None, source: ~pathlib.Path | None = None, logger=<robot.output.logger.Logger object>)[source]
Bases:
ClassLibrary
- class robot.running.testlibraries.DynamicLibrary(code: type | ~types.ModuleType, init: ~robot.running.librarykeyword.LibraryInit, name: str | None = None, real_name: str | None = None, source: ~pathlib.Path | None = None, logger=<robot.output.logger.Logger object>)[source]
Bases:
ClassLibrary
- property supports_named_args: bool
- property doc: str
- class robot.running.testlibraries.KeywordCreator(library: TestLibrary, getting_method_failed_level='INFO')[source]
Bases:
object
- class robot.running.testlibraries.StaticKeywordCreator(library: TestLibrary, getting_method_failed_level='INFO', excluded_names=None, avoid_properties=False)[source]
Bases:
KeywordCreator
- class robot.running.testlibraries.DynamicKeywordCreator(library: DynamicLibrary | HybridLibrary)[source]
Bases:
KeywordCreator
- library: DynamicLibrary
robot.running.userkeywordrunner module
- class robot.running.userkeywordrunner.UserKeywordRunner(keyword: UserKeyword, name: str | None = None)[source]
Bases:
object
- class robot.running.userkeywordrunner.EmbeddedArgumentsRunner(keyword: UserKeyword, name: str)[source]
Bases:
UserKeywordRunner