37 if 'robot' not in sys.modules
and __name__ ==
'__main__':
38 import pythonpathsetter
48 from robot.run
import USAGE
50 USAGE =
"""Robot Framework -- A generic automation framework
54 Usage: robot [options] data_sources
55 or: python -m robot [options] data_sources
56 or: python path/to/robot [options] data_sources
57 or: java -jar robotframework.jar [options] data_sources
59 Robot Framework is a generic open source automation framework for acceptance
60 testing, acceptance test-driven development (ATDD) and robotic process
61 automation (RPA). It has simple, easy-to-use syntax that utilizes the
62 keyword-driven automation approach. Keywords adding new capabilities are
63 implemented in libraries using either Python or Java. New higher level
64 keywords can also be created using Robot Framework's own syntax.
66 The easiest way to execute Robot Framework is using the `robot` command created
67 as part of the normal installation. Alternatively it is possible to execute
68 the `robot` module directly using `python -m robot`, where `python` can be
69 replaced with any supported Python interpreter such as `jython`, `ipy` or
70 `python3`. Yet another alternative is running the `robot` directory like
71 `python path/to/robot`. Finally, there is a standalone JAR distribution
74 Tests (or tasks in RPA terminology) are created in files typically having the
75 `*.robot` extension. Files automatically create test (or task) suites and
76 directories with these files create higher level suites. When Robot Framework
77 is executed, paths to these files or directories are given to it as arguments.
79 By default Robot Framework creates an XML output file and a log and a report in
80 HTML format, but this can be configured using various options listed below.
81 Outputs in HTML format are for human consumption and XML output for integration
82 with other systems. XML outputs can also be combined and otherwise further
83 post-processed with the Rebot tool that is an integral part of Robot Framework.
84 Run `rebot --help` for more information.
86 Robot Framework is open source software released under Apache License 2.0.
87 For more information about the framework and the rich ecosystem around it
88 see http://robotframework.org/.
93 --rpa Turn on generic automation mode. Mainly affects
94 terminology so that "test" is replaced with "task"
95 in logs and reports. By default the mode is got
96 from test/task header in data files. New in RF 3.1.
97 -F --extension value Parse only files with this extension when executing
98 a directory. Has no effect when running individual
99 files or when using resource files. If more than one
100 extension is needed, separate them with a colon.
101 Examples: `--extension robot`, `-F robot:txt`
103 -N --name name Set the name of the top level test suite. Default
104 name is created from the name of the executed data
106 -D --doc documentation Set the documentation of the top level test suite.
107 Simple formatting is supported (e.g. *bold*). If
108 the documentation contains spaces, it must be quoted.
109 Example: --doc "Very *good* example"
110 -M --metadata name:value * Set metadata of the top level suite. Value can
111 contain formatting similarly as --doc.
112 Example: --metadata version:1.2
113 -G --settag tag * Sets given tag(s) to all executed test cases.
114 -t --test name * Select test cases to run by name or long name. Name
115 is case and space insensitive and it can also be a
116 simple pattern where `*` matches anything and `?`
118 --task name * Alias to --test. Especially applicable with --rpa.
119 -s --suite name * Select test suites to run by name. When this option
120 is used with --test, --include or --exclude, only
121 test cases in matching suites and also matching other
122 filtering criteria are selected. Name can be a simple
123 pattern similarly as with --test and it can contain
124 parent name separated with a dot. For example
125 `-s X.Y` selects suite `Y` only if its parent is `X`.
126 -i --include tag * Select test cases to run by tag. Similarly as name
127 with --test, tag is case and space insensitive and it
128 is possible to use patterns with `*` and `?` as
129 wildcards. Tags and patterns can also be combined
130 together with `AND`, `OR`, and `NOT` operators.
131 Examples: --include foo --include bar*
133 -e --exclude tag * Select test cases not to run by tag. These tests are
134 not run even if included with --include. Tags are
135 matched using the rules explained with --include.
136 -R --rerunfailed output Select failed tests from an earlier output file to be
137 re-executed. Equivalent to selecting same tests
138 individually using --test option.
139 -S --rerunfailedsuites output Select failed suite from an earlier output file
140 to be re-executed. New in RF 3.0.1.
141 -c --critical tag * Tests having given tag are considered critical. If no
142 critical tags are set, all tags are critical. Tags
143 can be given as a pattern like with --include.
144 -n --noncritical tag * Tests with given tag are not critical even if they
145 have a tag set with --critical. Tag can be a pattern.
146 -v --variable name:value * Set variables in the test data. Only scalar
147 variables with string value are supported and name is
148 given without `${}`. See --variablefile for a more
149 powerful variable setting mechanism.
151 --variable str:Hello => ${str} = `Hello`
152 -v hi:Hi_World -E space:_ => ${hi} = `Hi World`
153 -v x: -v y:42 => ${x} = ``, ${y} = `42`
154 -V --variablefile path * Python or YAML file file to read variables from.
155 Possible arguments to the variable file can be given
156 after the path using colon or semicolon as separator.
157 Examples: --variablefile path/vars.yaml
158 --variablefile environment.py:testing
159 -d --outputdir dir Where to create output files. The default is the
160 directory where tests are run from and the given path
161 is considered relative to that unless it is absolute.
162 -o --output file XML output file. Given path, similarly as paths given
163 to --log, --report, --xunit, and --debugfile, is
164 relative to --outputdir unless given as an absolute
165 path. Other output files are created based on XML
166 output files after the test execution and XML outputs
167 can also be further processed with Rebot tool. Can be
168 disabled by giving a special value `NONE`. In this
169 case, also log and report are automatically disabled.
171 -l --log file HTML log file. Can be disabled by giving a special
172 value `NONE`. Default: log.html
173 Examples: `--log mylog.html`, `-l NONE`
174 -r --report file HTML report file. Can be disabled with `NONE`
175 similarly as --log. Default: report.html
176 -x --xunit file xUnit compatible result file. Not created unless this
178 --xunitskipnoncritical Mark non-critical tests on xUnit output as skipped.
179 -b --debugfile file Debug file written during execution. Not created
180 unless this option is specified.
181 -T --timestampoutputs When this option is used, timestamp in a format
182 `YYYYMMDD-hhmmss` is added to all generated output
183 files between their basename and extension. For
184 example `-T -o output.xml -r report.html -l none`
185 creates files like `output-20070503-154410.xml` and
186 `report-20070503-154410.html`.
187 --splitlog Split log file into smaller pieces that open in
188 browser transparently.
189 --logtitle title Title for the generated test log. The default title
190 is `<Name Of The Suite> Test Log`.
191 --reporttitle title Title for the generated test report. The default
192 title is `<Name Of The Suite> Test Report`.
193 --reportbackground colors Background colors to use in the report file.
194 Either `all_passed:critical_passed:failed` or
195 `passed:failed`. Both color names and codes work.
196 Examples: --reportbackground green:yellow:red
197 --reportbackground #00E:#E00
198 --maxerrorlines lines Maximum number of error message lines to show in
199 report when tests fail. Default is 40, minimum is 10
200 and `NONE` can be used to show the full message.
201 -L --loglevel level Threshold level for logging. Available levels: TRACE,
202 DEBUG, INFO (default), WARN, NONE (no logging). Use
203 syntax `LOGLEVEL:DEFAULT` to define the default
204 visible log level in log files.
205 Examples: --loglevel DEBUG
206 --loglevel DEBUG:INFO
207 --suitestatlevel level How many levels to show in `Statistics by Suite`
208 in log and report. By default all suite levels are
209 shown. Example: --suitestatlevel 3
210 --tagstatinclude tag * Include only matching tags in `Statistics by Tag`
211 and `Test Details` in log and report. By default all
212 tags set in test cases are shown. Given `tag` can
213 also be a simple pattern (see e.g. --test).
214 --tagstatexclude tag * Exclude matching tags from `Statistics by Tag` and
215 `Test Details`. This option can be used with
216 --tagstatinclude similarly as --exclude is used with
218 --tagstatcombine tags:name * Create combined statistics based on tags.
219 These statistics are added into `Statistics by Tag`
220 and matching tests into `Test Details`. If optional
221 `name` is not given, name of the combined tag is got
222 from the specified tags. Tags are combined using the
223 rules explained in --include.
224 Examples: --tagstatcombine requirement-*
225 --tagstatcombine tag1ANDtag2:My_name
226 --tagdoc pattern:doc * Add documentation to tags matching given pattern.
227 Documentation is shown in `Test Details` and also as
228 a tooltip in `Statistics by Tag`. Pattern can contain
229 characters `*` (matches anything) and `?` (matches
230 any char). Documentation can contain formatting
231 similarly as with --doc option.
232 Examples: --tagdoc mytag:Example
233 --tagdoc "owner-*:Original author"
234 --tagstatlink pattern:link:title * Add external links into `Statistics by
235 Tag`. Pattern can contain characters `*` (matches
236 anything) and `?` (matches any char). Characters
237 matching to wildcard expressions can be used in link
238 and title with syntax %N, where N is index of the
239 match (starting from 1).
240 Examples: --tagstatlink mytag:http://my.domain:Title
241 --tagstatlink "bug-*:http://url/id=%1:Issue Tracker"
242 --removekeywords all|passed|for|wuks|name:<pattern>|tag:<pattern> *
243 Remove keyword data from the generated log file.
244 Keywords containing warnings are not removed except
246 all: remove data from all keywords
247 passed: remove data only from keywords in passed
248 test cases and suites
249 for: remove passed iterations from for loops
250 wuks: remove all but the last failing keyword
251 inside `BuiltIn.Wait Until Keyword Succeeds`
252 name:<pattern>: remove data from keywords that match
253 the given pattern. The pattern is matched
254 against the full name of the keyword (e.g.
255 'MyLib.Keyword', 'resource.Second Keyword'),
256 is case, space, and underscore insensitive,
257 and may contain `*` and `?` as wildcards.
258 Examples: --removekeywords name:Lib.HugeKw
259 --removekeywords name:myresource.*
260 tag:<pattern>: remove data from keywords that match
261 the given pattern. Tags are case and space
262 insensitive and it is possible to use
263 patterns with `*` and `?` as wildcards.
264 Tags and patterns can also be combined
265 together with `AND`, `OR`, and `NOT`
267 Examples: --removekeywords foo
268 --removekeywords fooANDbar*
269 --flattenkeywords for|foritem|name:<pattern>|tag:<pattern> *
270 Flattens matching keywords in the generated log file.
271 Matching keywords get all log messages from their
272 child keywords and children are discarded otherwise.
273 for: flatten for loops fully
274 foritem: flatten individual for loop iterations
275 name:<pattern>: flatten matched keywords using same
276 matching rules as with
277 `--removekeywords name:<pattern>`
278 tag:<pattern>: flatten matched keywords using same
279 matching rules as with
280 `--removekeywords tag:<pattern>`
281 --listener class * A class for monitoring test execution. Gets
282 notifications e.g. when a test case starts and ends.
283 Arguments to the listener class can be given after
284 the name using colon or semicolon as a separator.
285 Examples: --listener MyListenerClass
286 --listener path/to/Listener.py:arg1:arg2
287 --warnonskippedfiles Deprecated. Nowadays all skipped files are reported.
288 --nostatusrc Sets the return code to zero regardless of failures
289 in test cases. Error codes are returned normally.
290 --runemptysuite Executes tests also if the top level test suite is
291 empty. Useful e.g. with --include/--exclude when it
292 is not an error that no test matches the condition.
293 --dryrun Verifies test data and runs tests so that library
294 keywords are not executed.
295 -X --exitonfailure Stops test execution if any critical test fails.
296 Short option -X is new in RF 3.0.1.
297 --exitonerror Stops test execution if any error occurs when parsing
298 test data, importing libraries, and so on.
299 --skipteardownonexit Causes teardowns to be skipped if test execution is
301 --randomize all|suites|tests|none Randomizes the test execution order.
302 all: randomizes both suites and tests
303 suites: randomizes suites
304 tests: randomizes tests
305 none: no randomization (default)
306 Use syntax `VALUE:SEED` to give a custom random seed.
307 The seed must be an integer.
308 Examples: --randomize all
309 --randomize tests:1234
310 --prerunmodifier class * Class to programmatically modify the test suite
311 structure before execution.
312 --prerebotmodifier class * Class to programmatically modify the result
313 model before creating reports and logs.
314 --console type How to report execution on the console.
315 verbose: report every suite and test (default)
316 dotted: only show `.` for passed test, `f` for
317 failed non-critical tests, and `F` for
318 failed critical tests
319 quiet: no output except for errors and warnings
320 none: no output whatsoever
321 -. --dotted Shortcut for `--console dotted`.
322 --quiet Shortcut for `--console quiet`.
323 -W --consolewidth chars Width of the monitor output. Default is 78.
324 -C --consolecolors auto|on|ansi|off Use colors on console output or not.
325 auto: use colors when output not redirected (default)
326 on: always use colors
327 ansi: like `on` but use ANSI colors also on Windows
328 off: disable colors altogether
329 Note that colors do not work with Jython on Windows.
330 -K --consolemarkers auto|on|off Show markers on the console when top level
331 keywords in a test case end. Values have same
332 semantics as with --consolecolors.
333 -P --pythonpath path * Additional locations (directories, ZIPs, JARs) where
334 to search test libraries and other extensions when
335 they are imported. Multiple paths can be given by
336 separating them with a colon (`:`) or by using this
337 option several times. Given path can also be a glob
338 pattern matching multiple paths.
340 --pythonpath libs/ --pythonpath resources/*.jar
341 --pythonpath /opt/testlibs:mylibs.zip:yourlibs
342 -E --escape what:with * Deprecated. Use console escape mechanism instead.
343 -A --argumentfile path * Text file to read more arguments from. Use special
344 path `STDIN` to read contents from the standard input
345 stream. File can have both options and data sources
346 one per line. Contents do not need to be escaped but
347 spaces in the beginning and end of lines are removed.
348 Empty lines and lines starting with a hash character
351 | --include regression
352 | --name Regression Tests
353 | # This is a comment line
355 | path/to/test/directory/
357 --argumentfile argfile.txt --argumentfile STDIN
358 -h -? --help Print usage instructions.
359 --version Print version information.
361 Options that are marked with an asterisk (*) can be specified multiple times.
362 For example, `--test first --test third` selects test cases with name `first`
363 and `third`. If an option accepts a value but is not marked with an asterisk,
364 the last given value has precedence. For example, `--log A.html --log B.html`
365 creates log file `B.html`. Options accepting no values can be disabled by
366 using the same option again with `no` prefix added or dropped. The last option
367 has precedence regardless of how many times options are used. For example,
368 `--dryrun --dryrun --nodryrun --nostatusrc --statusrc` would not activate the
369 dry-run mode and would return normal status rc.
371 Long option format is case-insensitive. For example, --SuiteStatLevel is
372 equivalent to but easier to read than --suitestatlevel. Long options can
373 also be shortened as long as they are unique. For example, `--logti Title`
374 works while `--lo log.html` does not because the former matches only --logtitle
375 but the latter matches --log, --loglevel and --logtitle.
377 Environment Variables
378 =====================
380 ROBOT_OPTIONS Space separated list of default options to be placed
381 in front of any explicit options on the command line.
382 ROBOT_SYSLOG_FILE Path to a file where Robot Framework writes internal
383 information about parsing test case files and running
384 tests. Can be useful when debugging problems. If not
385 set, or set to a special value `NONE`, writing to the
386 syslog file is disabled.
387 ROBOT_SYSLOG_LEVEL Log level to use when writing to the syslog file.
388 Available levels are the same as with --loglevel
389 command line option and the default is INFO.
390 ROBOT_INTERNAL_TRACES When set to any non-empty value, Robot Framework's
391 internal methods are included in error tracebacks.
396 # Simple test run using `robot` command without options.
400 $ robot --include smoke --name "Smoke Tests" path/to/tests.robot
402 # Executing `robot` module using Python.
403 $ python -m robot path/to/tests
405 # Running `robot` directory with Jython.
406 $ jython /opt/robot tests.robot
408 # Executing multiple test case files and using case-insensitive long options.
409 $ robot --SuiteStatLevel 2 --Metadata Version:3 tests/*.robot more/tests.robot
411 # Setting default options and syslog file before running tests.
412 $ export ROBOT_OPTIONS="--critical regression --suitestatlevel 2"
413 $ export ROBOT_SYSLOG_FILE=/tmp/syslog.txt
421 Application.__init__(self, USAGE, arg_limits=(1,),
422 env_options=
'ROBOT_OPTIONS', logger=LOGGER)
424 def main(self, datasources, **options):
426 LOGGER.register_console_logger(**settings.console_output_config)
427 LOGGER.info(
'Settings:\n%s' %
unic(settings))
428 builder = TestSuiteBuilder(settings[
'SuiteNames'],
429 extension=settings.extension,
431 suite = builder.build(*datasources)
432 settings.rpa = builder.rpa
433 suite.configure(**settings.suite_config)
434 if settings.pre_run_modifiers:
436 settings.run_empty_suite, LOGGER))
437 with pyloggingconf.robot_handler_enabled(settings.log_level):
438 old_max_error_lines = text.MAX_ERROR_LINES
439 text.MAX_ERROR_LINES = settings.max_error_lines
441 result = suite.run(settings)
443 text.MAX_ERROR_LINES = old_max_error_lines
444 LOGGER.info(
"Tests execution ended. Statistics:\n%s"
445 % result.suite.stat_message)
446 if settings.log
or settings.report
or settings.xunit:
449 writer.write_results(settings.get_rebot_settings())
450 return result.return_code
456 return dict((name, value)
for name, value
in options.items()
457 if value
not in (
None, []))
488 if arguments
is None:
489 arguments = sys.argv[1:]
546 def run(*tests, **options):
550 if __name__ ==
'__main__':
A class to create log, report, output XML and xUnit files.
def _filter_options_without_value(self, options)
def validate(self, options, arguments)
def main(self, datasources, **options)
def run_cli(arguments=None, exit=True)
Command line execution entry point for running tests.
def run(*tests, **options)
Programmatic entry point for running tests.