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