Robot Framework
rebot.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright 2008-2015 Nokia Networks
4 # Copyright 2016- Robot Framework Foundation
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 
18 
32 
33 import sys
34 
35 # Allows running as a script. __name__ check needed with multiprocessing:
36 # https://github.com/robotframework/robotframework/issues/1137
37 if 'robot' not in sys.modules and __name__ == '__main__':
38  import pythonpathsetter
39 
40 from robot.conf import RebotSettings
41 from robot.errors import DataError
42 from robot.reporting import ResultWriter
43 from robot.output import LOGGER
44 from robot.utils import Application
45 from robot.run import RobotFramework
46 
47 
48 USAGE = """Rebot -- Robot Framework report and log generator
49 
50 Version: <VERSION>
51 
52 Usage: rebot [options] robot_outputs
53  or: python -m robot.rebot [options] robot_outputs
54  or: python path/to/robot/rebot.py [options] robot_outputs
55 
56 Rebot can be used to generate logs and reports in HTML format. It can also
57 produce new XML output files which can be further processed with Rebot or
58 other tools.
59 
60 The easiest way to execute Rebot is using the `rebot` command created as part
61 of the normal installation. Alternatively it is possible to execute the
62 `robot.rebot` module directly using `python -m robot.rebot`, where `python`
63 can be replaced with any supported Python interpreter. Yet another alternative
64 is running the `robot/rebot.py` script like `python path/to/robot/rebot.py`.
65 
66 Inputs to Rebot are XML output files generated by Robot Framework or by earlier
67 Rebot executions. When more than one input file is given, a new top level test
68 suite containing suites in the given files is created by default. This allows
69 combining multiple outputs together to create higher level reports. An
70 exception is that if --merge is used, results are combined by adding suites
71 and tests in subsequent outputs into the first suite structure. If same test
72 is found from multiple outputs, the last one replaces the earlier ones.
73 
74 For more information about Rebot and other built-in tools, see
75 http://robotframework.org/robotframework/#built-in-tools. For more details
76 about Robot Framework in general, go to http://robotframework.org.
77 
78 Options
79 =======
80 
81  --rpa Turn on the generic automation mode. Mainly affects
82  terminology so that "test" is replaced with "task"
83  in logs and reports. By default the mode is got
84  from the processed output files.
85  -R --merge When combining results, merge outputs together
86  instead of putting them under a new top level suite.
87  Example: rebot --merge orig.xml rerun.xml
88  -N --name name Set the name of the top level suite.
89  -D --doc documentation Set the documentation of the top level suite.
90  Simple formatting is supported (e.g. *bold*). If
91  the documentation contains spaces, it must be quoted.
92  If the value is path to an existing file, actual
93  documentation is read from that file.
94  Examples: --doc "Very *good* example"
95  --doc doc_from_file.txt
96  -M --metadata name:value * Set metadata of the top level suite. Value can
97  contain formatting and be read from a file similarly
98  as --doc. Example: --metadata Version:1.2
99  -G --settag tag * Sets given tag(s) to all tests.
100  -t --test name * Select tests by name or by long name containing also
101  parent suite name like `Parent.Test`. Name is case
102  and space insensitive and it can also be a simple
103  pattern where `*` matches anything, `?` matches any
104  single character, and `[chars]` matches one character
105  in brackets.
106  --task name * Alias to --test. Especially applicable with --rpa.
107  -s --suite name * Select suites by name. When this option is used with
108  --test, --include or --exclude, only tests in
109  matching suites and also matching other filtering
110  criteria are selected. Name can be a simple pattern
111  similarly as with --test and it can contain parent
112  name separated with a dot. For example, `-s X.Y`
113  selects suite `Y` only if its parent is `X`.
114  -i --include tag * Select tests by tag. Similarly as name with --test,
115  tag is case and space insensitive and it is possible
116  to use patterns with `*`, `?` and `[]` as wildcards.
117  Tags and patterns can also be combined together with
118  `AND`, `OR`, and `NOT` operators.
119  Examples: --include foo --include bar*
120  --include fooANDbar*
121  -e --exclude tag * Specify tests not to be included by tag. They are not
122  selected even if included with --include. Tags are
123  matched using same rules as with --include.
124  --processemptysuite Processes output also if the top level suite is
125  empty. Useful e.g. with --include/--exclude when it
126  is not an error that there are no matches.
127  Use --skiponfailure when starting execution instead.
128  -d --outputdir dir Where to create output files. The default is the
129  directory where Rebot is run from and the given path
130  is considered relative to that unless it is absolute.
131  -o --output file XML output file. Not created unless this option is
132  specified. Given path, similarly as paths given to
133  --log, --report and --xunit, is relative to
134  --outputdir unless given as an absolute path.
135  -l --log file HTML log file. Can be disabled by giving a special
136  name `NONE`. Default: log.html
137  Examples: `--log mylog.html`, `-l none`
138  -r --report file HTML report file. Can be disabled with `NONE`
139  similarly as --log. Default: report.html
140  -x --xunit file xUnit compatible result file. Not created unless this
141  option is specified.
142  -T --timestampoutputs When this option is used, timestamp in a format
143  `YYYYMMDD-hhmmss` is added to all generated output
144  files between their basename and extension. For
145  example `-T -o output.xml -r report.html -l none`
146  creates files like `output-20070503-154410.xml` and
147  `report-20070503-154410.html`.
148  --splitlog Split the log file into smaller pieces that open in
149  browsers transparently.
150  --logtitle title Title for the generated log file. The default title
151  is `<SuiteName> Log`.
152  --reporttitle title Title for the generated report file. The default
153  title is `<SuiteName> Report`.
154  --reportbackground colors Background colors to use in the report file.
155  Given in format `passed:failed:skipped` where the
156  `:skipped` part can be omitted. Both color names and
157  codes work.
158  Examples: --reportbackground green:red:yellow
159  --reportbackground #00E:#E00
160  -L --loglevel level Threshold for selecting messages. Available levels:
161  TRACE (default), DEBUG, INFO, WARN, NONE (no msgs).
162  Use syntax `LOGLEVEL:DEFAULT` to define the default
163  visible log level in log files.
164  Examples: --loglevel DEBUG
165  --loglevel DEBUG:INFO
166  --suitestatlevel level How many levels to show in `Statistics by Suite`
167  in log and report. By default all suite levels are
168  shown. Example: --suitestatlevel 3
169  --tagstatinclude tag * Include only matching tags in `Statistics by Tag`
170  in log and report. By default all tags are shown.
171  Given tag can be a pattern like with --include.
172  --tagstatexclude tag * Exclude matching tags from `Statistics by Tag`.
173  This option can be used with --tagstatinclude
174  similarly as --exclude is used with --include.
175  --tagstatcombine tags:name * Create combined statistics based on tags.
176  These statistics are added into `Statistics by Tag`.
177  If the optional `name` is not given, name of the
178  combined tag is got from the specified tags. Tags are
179  matched using the same rules as with --include.
180  Examples: --tagstatcombine requirement-*
181  --tagstatcombine tag1ANDtag2:My_name
182  --tagdoc pattern:doc * Add documentation to tags matching the given
183  pattern. Documentation is shown in `Test Details` and
184  also as a tooltip in `Statistics by Tag`. Pattern can
185  use `*`, `?` and `[]` as wildcards like --test.
186  Documentation can contain formatting like --doc.
187  Examples: --tagdoc mytag:Example
188  --tagdoc "owner-*:Original author"
189  --tagstatlink pattern:link:title * Add external links into `Statistics by
190  Tag`. Pattern can use `*`, `?` and `[]` as wildcards
191  like --test. Characters matching to `*` and `?`
192  wildcards can be used in link and title with syntax
193  %N, where N is index of the match (starting from 1).
194  Examples: --tagstatlink mytag:http://my.domain:Title
195  --tagstatlink "bug-*:http://url/id=%1:Issue Tracker"
196  --expandkeywords name:<pattern>|tag:<pattern> *
197  Matching keywords will be automatically expanded in
198  the log file. Matching against keyword name or tags
199  work using same rules as with --removekeywords.
200  Examples: --expandkeywords name:BuiltIn.Log
201  --expandkeywords tag:expand
202  --removekeywords all|passed|for|wuks|name:<pattern>|tag:<pattern> *
203  Remove keyword data from all generated outputs.
204  Keywords containing warnings are not removed except
205  in the `all` mode.
206  all: remove data from all keywords
207  passed: remove data only from keywords in passed
208  test cases and suites
209  for: remove passed iterations from for loops
210  while: remove passed iterations from while loops
211  wuks: remove all but the last failing keyword
212  inside `BuiltIn.Wait Until Keyword Succeeds`
213  name:<pattern>: remove data from keywords that match
214  the given pattern. The pattern is matched
215  against the full name of the keyword (e.g.
216  'MyLib.Keyword', 'resource.Second Keyword'),
217  is case, space, and underscore insensitive,
218  and may contain `*`, `?` and `[]` wildcards.
219  Examples: --removekeywords name:Lib.HugeKw
220  --removekeywords name:myresource.*
221  tag:<pattern>: remove data from keywords that match
222  the given pattern. Tags are case and space
223  insensitive and patterns can contain `*`,
224  `?` and `[]` wildcards. Tags and patterns
225  can also be combined together with `AND`,
226  `OR`, and `NOT` operators.
227  Examples: --removekeywords foo
228  --removekeywords fooANDbar*
229  --flattenkeywords for|while|iteration|name:<pattern>|tag:<pattern> *
230  Flattens matching keywords in all generated outputs.
231  Matching keywords get all log messages from their
232  child keywords and children are discarded otherwise.
233  for: flatten FOR loops fully
234  while: flatten WHILE loops fully
235  iteration: flatten FOR/WHILE loop iterations
236  foritem: deprecated alias for `iteration`
237  name:<pattern>: flatten matched keywords using same
238  matching rules as with
239  `--removekeywords name:<pattern>`
240  tag:<pattern>: flatten matched keywords using same
241  matching rules as with
242  `--removekeywords tag:<pattern>`
243  --starttime timestamp Set execution start time. Timestamp must be given in
244  format `2007-10-01 15:12:42.268` where all separators
245  are optional (e.g. `20071001151242268` is ok too) and
246  parts from milliseconds to hours can be omitted if
247  they are zero (e.g. `2007-10-01`). This can be used
248  to override start time of a single suite or to set
249  start time for a combined suite, which would
250  otherwise be `N/A`.
251  --endtime timestamp Same as --starttime but for end time. If both options
252  are used, elapsed time of the suite is calculated
253  based on them. For combined suites, it is otherwise
254  calculated by adding elapsed times of the combined
255  suites together.
256  --nostatusrc Sets the return code to zero regardless are there
257  failures. Error codes are returned normally.
258  --prerebotmodifier class * Class to programmatically modify the result
259  model before creating outputs.
260  -C --consolecolors auto|on|ansi|off Use colors on console output or not.
261  auto: use colors when output not redirected (default)
262  on: always use colors
263  ansi: like `on` but use ANSI colors also on Windows
264  off: disable colors altogether
265  -P --pythonpath path * Additional locations to add to the module search path
266  that is used when importing Python based extensions.
267  -A --argumentfile path * Text file to read more arguments from. File can have
268  both options and output files, one per line. Contents
269  do not need to be escaped but spaces in the beginning
270  and end of lines are removed. Empty lines and lines
271  starting with a hash character (#) are ignored.
272  Example file:
273  | --include regression
274  | --name Regression Tests
275  | # This is a comment line
276  | output.xml
277  -h -? --help Print usage instructions.
278  --version Print version information.
279 
280 Options that are marked with an asterisk (*) can be specified multiple times.
281 For example, `--test first --test third` selects test cases with name `first`
282 and `third`. If an option accepts a value but is not marked with an asterisk,
283 the last given value has precedence. For example, `--log A.html --log B.html`
284 creates log file `B.html`. Options accepting no values can be disabled by
285 using the same option again with `no` prefix added or dropped. The last option
286 has precedence regardless of how many times options are used. For example,
287 `--merge --merge --nomerge --nostatusrc --statusrc` would not activate the
288 merge mode and would return a normal return code.
289 
290 Long option format is case-insensitive. For example, --SuiteStatLevel is
291 equivalent to but easier to read than --suitestatlevel. Long options can
292 also be shortened as long as they are unique. For example, `--logti Title`
293 works while `--lo log.html` does not because the former matches only --logtitle
294 but the latter matches both --log and --logtitle.
295 
296 Environment Variables
297 =====================
298 
299 REBOT_OPTIONS Space separated list of default options to be placed
300  in front of any explicit options on the command line.
301 ROBOT_SYSLOG_FILE Path to a file where Robot Framework writes internal
302  information about processed files. Can be useful when
303  debugging problems. If not set, or set to special
304  value `NONE`, writing to the syslog file is disabled.
305 ROBOT_SYSLOG_LEVEL Log level to use when writing to the syslog file.
306  Available levels are the same as for --loglevel
307  command line option and the default is INFO.
308 
309 Examples
310 ========
311 
312 # Simple Rebot run that creates log and report with default names.
313 $ rebot output.xml
314 
315 # Using options. Note that this is one long command split into multiple lines.
316 $ rebot --log smoke_log.html --report smoke_report.html --include smoke
317  --ReportTitle "Smoke Tests" --ReportBackground green:yellow:red
318  --TagStatCombine tag1ANDtag2 path/to/myoutput.xml
319 
320 # Executing `robot.rebot` module using Python and creating combined outputs.
321 $ python -m robot.rebot --name Combined outputs/*.xml
322 """
323 
324 
326 
327  def __init__(self):
328  Application.__init__(self, USAGE, arg_limits=(1,), env_options='REBOT_OPTIONS',
329  logger=LOGGER)
330 
331  def main(self, datasources, **options):
332  try:
333  settings = RebotSettings(options)
334  except:
335  LOGGER.register_console_logger(stdout=options.get('stdout'),
336  stderr=options.get('stderr'))
337  raise
338  LOGGER.register_console_logger(**settings.console_output_config)
339  if settings.pythonpath:
340  sys.path = settings.pythonpath + sys.path
341  LOGGER.disable_message_cache()
342  rc = ResultWriter(*datasources).write_results(settings)
343  if rc < 0:
344  raise DataError('No outputs created.')
345  return rc
346 
347 
348 
371 def rebot_cli(arguments=None, exit=True):
372  if arguments is None:
373  arguments = sys.argv[1:]
374  return Rebot().execute_cli(arguments, exit=exit)
375 
376 
377 
402 def rebot(*outputs, **options):
403  return Rebot().execute(*outputs, **options)
404 
405 
406 if __name__ == '__main__':
407  rebot_cli(sys.argv[1:])
def __init__(self)
Definition: rebot.py:327
def main(self, datasources, **options)
Definition: rebot.py:331
def rebot_cli(arguments=None, exit=True)
Command line execution entry point for post-processing outputs.
Definition: rebot.py:371
def rebot(*outputs, **options)
Programmatic entry point for post-processing outputs.
Definition: rebot.py:402
Definition: run.py:1