Commit 38300adc authored by Michele Carignani's avatar Michele Carignani
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading

.gitignore

0 → 100644
+4 −0
Original line number Diff line number Diff line
*.docx
*.pyc
.vscode/
 No newline at end of file

ETSI_GS_skeleton.docx

0 → 100644
+119 KiB

File added.

No diff preview for this file type.

Readme.md

0 → 100644
+40 −0
Original line number Diff line number Diff line
# robot2doc

A simple Docx generator for Robot Framework Test Suites

## Requirements

    pip install

## Usage

    python main.py <robot-tests> [OUT_FILENAME [SECTION_TITLE]]

Command line arguments:

* `robot-tests` a folder or a file containing Robot tests
* `OUT_FILENAME` filename for the output (e.g. `my-tests.docx`)
* `SECTION_TITLE` the title for the section in the doc where the tests are included

## How to write the tests

For each test in each test suite, the tool will extract the documentation and parse
each line as a key-value pair, separated by `:`.

If the separator is not present, the entire line is used as the value and the key
is omitted.

Example:

    [Documentation]    Test Name: This is the test name. 
        ...    Another key: Another value. 
        ...    This line does not present a key, therefore the key is omitted. 
        ...    Post-conditions: After the test you will be happy.
        Log    Test starts...
        Etc. etc.

## License

Released under the ETSI Software Licese

https://forge.etsi.org/etsi-software-license

main.py

0 → 100644
+77 −0
Original line number Diff line number Diff line
#!/env/python
#
#  Usage: python main.py <FILE_OR_FOLDER> [OUTPUT_FILENAME [MAIN_TITLE]]
#

from robot.api import TestSuiteBuilder
import sys
import testspec
from testpurpose import TP

# Configuration

DOC_MAIN_TITLE = 'Annex B (informative): Test Cases'
DOC_FILENAME = 'test_spec_from_robot.docx'
FILE=""
        
def keyword_to_line(k):
    '''
    Takes a Robot Framework keyword object and returns
    a string with keyword and arguments on a single line
    '''
    return str(k) + " " + " ".join(k.args)

def keywords_to_text(ks):
    '''
    Takes a list of Robot Framework words and returns a multiline text 
    '''
    return "\n".join(map(keyword_to_line, ks))

def robot2doc(src, doc_fn, doc_main_tit):
    '''
    Converts a Robot test suite to a word document

    src            file or directory containing Robot tests

    doc_fn         the filename for the output

    doc_main_tit   top level title for the section in the doc
    '''

    print "Starting.."
    spec = testspec.TestSpec('ETSI_GS_Skeleton.docx')

    try:
        workspace = TestSuiteBuilder().build(file)
    except:
        print "Please check that first argument is a folder of Robot files or a single file."
        exit(-1)

    print "Loaded "+ str(len(workspace.suites)) + " test suites."
    sec = testspec.DOC_BASE_SEC - 1

    spec.add_main_heading(doc_main_tit)
    for suite in workspace.suites:
        sec = sec + 1
        subsec = 0
        print "  Generating test suite: " + str(suite)
        spec.add_sub_heading(str(suite),sec)
        for i in suite.tests:
            subsec = subsec + 1
            spec.add_heading(str(i), testspec.DOC_TC_LEVEL, sec, subsec)
            TP(i.doc).add_to_spec(spec, keywords_to_text(i.keywords))

    spec.save(doc_fn)
    print "Finished."

if __name__ == "__main__":

    if len(sys.argv) < 2:
        print "Usage: robot2doc <robot_file_or_dir> [<out_file> [spec_section_title]]"

    FILE = sys.argv[1]
    DOC_FILENAME = sys.argv[2] if len(sys.argv) > 2 else DOC_FILENAME
    DOC_MAIN_TITLE = sys.argv[3] if len(sys.argv) > 3 else DOC_MAIN_TITLE

    robot2doc(FILE, DOC_FILENAME, DOC_MAIN_TITLE)
 No newline at end of file

requirements.txt

0 → 100644
+4 −0
Original line number Diff line number Diff line
python-docx==0.8.7
robot==20071211
robotframework==3.0.4
 No newline at end of file