robot module¶
The root of the Robot Framework package.
The command line entry points provided by the framework are exposed for programmatic usage as follows:
run(): Function to run tests.
run_cli(): Function to run tests with command line argument processing.
rebot(): Function to post-process outputs.
rebot_cli(): Function to post-process outputs with command line argument processing.
libdoc: Module for library documentation generation.
testdoc: Module for test case documentation generation.
All the functions above can be imported like from robot import run.
Functions and classes provided by the modules need to be imported like
from robot.libdoc import libdoc_cli.
The functions and modules listed above are considered stable. Other modules in this package are for for internal usage and may change without prior notice.
Tip
More public APIs are exposed by the robot.api package.
- robot.rebot(*outputs, **options)¶
Programmatic entry point for post-processing outputs.
- Parameters
outputs – Paths to Robot Framework output files similarly as when running the
rebotcommand on the command line.options – Options to configure processing outputs. Accepted options are mostly same as normal command line options to the
rebotcommand. Option names match command line option long names without hyphens so that, for example,--namebecomesname.
The semantics related to passing options are exactly the same as with the
run()function. See its documentation for more details.Examples:
from robot import rebot rebot('path/to/output.xml') with open('stdout.txt', 'w') as stdout: rebot('o1.xml', 'o2.xml', name='Example', log=None, stdout=stdout)
Equivalent command line usage:
rebot path/to/output.xml rebot --name Example --log NONE o1.xml o2.xml > stdout.txt
- robot.rebot_cli(arguments=None, exit=True)¶
Command line execution entry point for post-processing outputs.
- Parameters
arguments – Command line options and arguments as a list of strings. Defaults to
sys.argv[1:]if not given.exit – If
True, callsys.exitwith the return code denoting execution status, otherwise just return the rc.
Entry point used when post-processing outputs from the command line, but can also be used by custom scripts. Especially useful if the script itself needs to accept same arguments as accepted by Rebot, because the script can just pass them forward directly along with the possible default values it sets itself.
Example:
from robot import rebot_cli rebot_cli(['--name', 'Example', '--log', 'NONE', 'o1.xml', 'o2.xml'])
See also the
rebot()function that allows setting options as keyword arguments likename="Example"and generally has a richer API for programmatic Rebot execution.
- robot.run(*tests, **options)¶
Programmatic entry point for running tests.
- Parameters
tests – Paths to test case files/directories to be executed similarly as when running the
robotcommand on the command line.options – Options to configure and control execution. Accepted options are mostly same as normal command line options to the
robotcommand. Option names match command line option long names without hyphens so that, for example,--namebecomesname.
Most options that can be given from the command line work. An exception is that options
--pythonpath,--argumentfile,--helpand--versionare not supported.Options that can be given on the command line multiple times can be passed as lists. For example,
include=['tag1', 'tag2']is equivalent to--include tag1 --include tag2. If such options are used only once, they can be given also as a single string likeinclude='tag'.Options that accept no value can be given as Booleans. For example,
dryrun=Trueis same as using the--dryrunoption.Options that accept string
NONEas a special value can also be used with PythonNone. For example, usinglog=Noneis equivalent to--log NONE.listener,prerunmodifierandprerebotmodifieroptions allow passing values as Python objects in addition to module names these command line options support. For example,run('tests', listener=MyListener()).To capture the standard output and error streams, pass an open file or file-like object as special keyword arguments
stdoutandstderr, respectively.A return code is returned similarly as when running on the command line. Zero means that tests were executed and no test failed, values up to 250 denote the number of failed tests, and values between 251-255 are for other statuses documented in the Robot Framework User Guide.
Example:
from robot import run run('path/to/tests.robot') run('tests.robot', include=['tag1', 'tag2'], splitlog=True) with open('stdout.txt', 'w') as stdout: run('t1.robot', 't2.robot', name='Example', log=None, stdout=stdout)
Equivalent command line usage:
robot path/to/tests.robot robot --include tag1 --include tag2 --splitlog tests.robot robot --name Example --log NONE t1.robot t2.robot > stdout.txt
- robot.run_cli(arguments=None, exit=True)¶
Command line execution entry point for running tests.
- Parameters
arguments – Command line options and arguments as a list of strings. Defaults to
sys.argv[1:]if not given.exit – If
True, callsys.exitwith the return code denoting execution status, otherwise just return the rc.
Entry point used when running tests from the command line, but can also be used by custom scripts that execute tests. Especially useful if the script itself needs to accept same arguments as accepted by Robot Framework, because the script can just pass them forward directly along with the possible default values it sets itself.
Example:
from robot import run_cli # Run tests and return the return code. rc = run_cli(['--name', 'Example', 'tests.robot'], exit=False) # Run tests and exit to the system automatically. run_cli(['--name', 'Example', 'tests.robot'])
See also the
run()function that allows setting options as keyword arguments likename="Example"and generally has a richer API for programmatic test execution.