38 if 'robot' not in sys.modules
and __name__ ==
'__main__':
39 import pythonpathsetter
46 html_escape, html_format, IRONPYTHON, is_string,
47 PY_VERSION, secs_to_timestr, seq2str2,
48 timestr_to_secs, unescape)
52 if IRONPYTHON
and PY_VERSION < (2, 7, 2):
56 USAGE =
"""robot.testdoc -- Robot Framework test data documentation tool
60 Usage: python -m robot.testdoc [options] data_sources output_file
62 Testdoc generates a high level test documentation based on Robot Framework
63 test data. Generated documentation includes name, documentation and other
64 metadata of each test suite and test case, as well as the top-level keywords
70 -T --title title Set the title of the generated documentation.
71 Underscores in the title are converted to spaces.
72 The default title is the name of the top level suite.
73 -N --name name Override the name of the top level suite.
74 -D --doc document Override the documentation of the top level suite.
75 -M --metadata name:value * Set/override metadata of the top level suite.
76 -G --settag tag * Set given tag(s) to all test cases.
77 -t --test name * Include tests by name.
78 -s --suite name * Include suites by name.
79 -i --include tag * Include tests by tags.
80 -e --exclude tag * Exclude tests by tags.
81 -A --argumentfile path * Text file to read more arguments from. Use special
82 path `STDIN` to read contents from the standard input
83 stream. File can have both options and data sources
84 one per line. Contents do not need to be escaped but
85 spaces in the beginning and end of lines are removed.
86 Empty lines and lines starting with a hash character
87 (#) are ignored. New in Robot Framework 3.0.2.
90 | # This is a comment line
94 --argumentfile argfile.txt --argumentfile STDIN
95 -h -? --help Print this help.
97 All options except --title have exactly same semantics as same options have
98 when executing test cases.
103 Data can be given as a single file, directory, or as multiple files and
104 directories. In all these cases, the last argument must be the file where
105 to write the output. The output is always created in HTML format.
107 Testdoc works with all interpreters supported by Robot Framework (Python,
108 Jython and IronPython). It can be executed as an installed module like
109 `python -m robot.testdoc` or as a script like `python path/robot/testdoc.py`.
113 python -m robot.testdoc my_test.html testdoc.html
114 jython -m robot.testdoc -N smoke_tests -i smoke path/to/my_tests smoke.html
115 ipy path/to/robot/testdoc.py first_suite.txt second_suite.txt output.html
117 For more information about Testdoc and other built-in tools, see
118 http://robotframework.org/robotframework/#built-in-tools.
125 Application.__init__(self, USAGE, arg_limits=(2,))
127 def main(self, datasources, title=None, **options):
128 outfile =
abspath(datasources.pop())
131 self.console(outfile)
139 @disable_curdir_processing
143 datasources = [datasources]
145 suite.configure(**settings.suite_config)
155 self.
_title_title = title.replace(
'_',
' ')
if title
else suite.name
158 self.
_output_output.
write(
'<script type="text/javascript">\n')
165 'title': self.
_title_title,
166 'generated':
int(time.time() * 1000)
181 'source': suite.source
or '',
184 'name': self.
_escape_escape(suite.name),
185 'fullName': self.
_escape_escape(suite.longname),
186 'doc': self.
_html_html(suite.doc),
187 'metadata': [(self.
_escape_escape(name), self.
_html_html(value))
188 for name, value
in suite.metadata.items()],
189 'numberOfTests': suite.test_count ,
207 return [self.
_convert_suite_convert_suite(s)
for s
in suite.suites]
210 return [self.
_convert_test_convert_test(t)
for t
in suite.tests]
214 'name': self.
_escape_escape(test.name),
215 'fullName': self.
_escape_escape(test.longname),
217 'doc': self.
_html_html(test.doc),
218 'tags': [self.
_escape_escape(t)
for t
in test.tags],
224 for kw
in getattr(item,
'keywords', []):
225 if kw.type == kw.SETUP_TYPE:
227 elif kw.type == kw.TEARDOWN_TYPE:
229 elif kw.type == kw.FOR_LOOP_TYPE:
244 'arguments': self.
_escape_escape(
', '.join(kw.args)),
250 return '%s = %s' % (
', '.join(a.rstrip(
'= ')
for a
in kw.assign), kw.name)
254 joiner =
' %s ' % kw.flavor
255 return ', '.join(kw.variables) + joiner +
seq2str2(kw.values)
265 tout +=
' :: ' + timeout.message
284 TestDoc().execute_cli(arguments)
299 TestDoc().execute(*arguments, **options)
302 if __name__ ==
'__main__':
Creates executable :class:~robot.running.model.TestSuite objects.
def _convert_tests(self, suite)
def _convert_suites(self, suite)
def _convert_test(self, test)
def _convert_keywords(self, item)
def _get_timeout(self, timeout)
def _get_relative_source(self, source)
def __init__(self, output_path=None)
def _get_kw_name(self, kw)
def _convert_keyword(self, kw, kw_type)
def _get_for_loop(self, kw)
def _convert_suite(self, suite)
def _convert_for_loop(self, kw)
def main(self, datasources, title=None, **options)
def _write_test_doc(self, suite, outfile, title)
def __init__(self, output, suite, title=None)
def write(msg, level='INFO', html=False)
Writes the message to the log file using the given level.
def testdoc_cli(arguments)
Executes Testdoc similarly as from the command line.
def TestSuiteFactory(datasources, **options)
def testdoc(*arguments, **options)
Executes Testdoc programmatically.
def html_escape(text, linkify=True)
def seq2str2(sequence)
Returns sequence in format [ item 1 | item 2 | ...
def file_writer(path=None, encoding='UTF-8', newline=None)
def abspath(path, case_normalize=False)
Replacement for os.path.abspath with some enhancements and bug fixes.
def get_link_path(target, base)
Returns a relative path to target from base.
def secs_to_timestr(secs, compact=False)
Converts time in seconds to a string representation.
def timestr_to_secs(timestr, round_to=3)
Parses time like '1h 10s', '01:00:10' or '42' and returns seconds.