Tuesday, July 9, 2013

Running robot tests from rst test files

Current rst parser of robotframework recognizes just the test cases in rst format inside the rest files.

To run the text cases in rst files, it has to be first extracted into a separate file and run using text parser.

The extraction can be done by two methods, either by using regex or by using docutils.

In implementation using regex, to detect the literal block, some prefix or suffix needs to be added so that it doesn't consider the statements after the literal blocks used in the statements as test cases.
 eg. in the following statement "Create an example ReST-file with multiple ``.. code:: robotframework``
   -parts and figure out," ".code::robotframework" is the literal block, but  " -parts and figure out," should not be confused with the test case.
Also an indication has to be made to inform that test case has ended.
So while using regex a lot of changes has to be made in the predefined format.

So on the safer side, docutils can be used to bring out the txt test cases. This can be done by forming the doctree using docutils. Then each nodes of  the doctree can be traversed to find if the tagname of the node is the desired literal block. If desired tagname is found at any node, the content of that node can be appended in a temporary file. After the completion of traversal, the temporary file contains all the txt test cases present in the rst file. This temporary file can be run using text parser of robot framework.