robotidy.py

robotidy.py is a tool for cleaning up Robot Framework test data. It is included in source distributions and can also be downloaded from http://code.google.com/p/robotframework/wiki/TestDataTidyingTool.

Synopsis

robotidy.py [options] inputfile outputfile
robotidy.py --inplace [options] inputfile [more input files]
robotidy.py --recursive [options] directory

Options

-I, --inplace Cleans given file(s) so that original file(s) are overwritten. When this option is used, it is possible to give multiple files at once. Examples: robotidy.py --inplace tests.html, robotidy.py --inplace --fixcomments *.html
-R, --recursive
 Processes the given directory recursively. Files in the directory are processed in place, similarly as when the --inplace option is used.
-X, --fixcomments
 Fixes comments in the test data.
-F, --format <html|tsv|txt>
 Format to use for output. Possible values are HTML, TSV and TXT. If this option is not used, the format is got from the extension of the output file.
-T, --title text
 The title to use in the test data. By default, the title is got from the name of the output file. If the output file is HTML, the title is used with "h1" and "title" tags, and with TSV and TXT it is simply printed before the first table. Possible underscores in the given title are converted to spaces.
-S, --style <path>
 Reads styles from an external style sheet file and replaces the default styles with them. If the path has a special value NONE, no styles are used. This setting is applicable only when the output format is HTML.
-h, --help Prints this help.

Description

This multipurpose tool has three usages explained in this section. In all cases, the outputs are written in the UTF-8 format.

Cleaning up the test data

The source code created by most HTML editors does not look very good. With this tool, the source can be formatted nicely, and it is even possible to specify a custom style sheet. Additionally, test data itself is cleaned up, so that settings and metadata are always in the same, predefined order.

Examples:

robotidy.py messed_up_tests.html cleaned_tests.html
robotidy.py --style new_styles.css my_tests.html my_tests.html

Changing format between HTML, TSV and TXT

Robot Framework supports test data in HTML, TSV and TXT formats, and this tool eases changing between formats. The input format is always determined from the extension of the input file. The output format is also got from the output file extension by default, but it can also be set explicitly with the --format option.

Examples:

robotidy.py tests_in_html.html tests_in_tsv.tsv
robotidy.py tests_in_tsv.tsv tests_in_txt.txt
robotidy.py --format html tests.tsv tests.xxx

Fixing comments

RIDE is a great tool for editing the test data, but at least currently, it totally ignores comments. This tool can be used to convert comments, so that they are not lost when the test data is opened in RIDE. Comments in Test Case and Keyword tables are changed, so that instead of #, a built-in Comment keyword is used. In Variable tables, comments are converted to @{#} or ${#}. Comments in Setting tables are not fixed.

Examples:

robotidy.py --fixcomments orig.html fixed.html
robotidy.py --fixcomments --inplace *.html

Fixing deprecated syntax for repeating keywords

Robot Framework has an old special syntax for repeating a single keyword. This syntax has been deprecated in 2.0.4 version in favor of built-in Repeat Keyword, and it will be removed altogether in 2.2 version. robotidy.py automatically replaces the deprecated syntax with Repeat Keyword.