Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse Robot Framework's output xml

Robot framework spits out an output XML which is then used to build the HTML reports (with rebot), re-run failures, etc.

I need to parse this file to generate other reports, in particular, I need to parse the test case's documentation for a regex, get the test case result and then build a report (this is for integration with a legacy system).

Does Robot Framework provide functionality to easily parse the output XML file or we just use standard XML parsing libraries?

like image 855
Joao Coelho Avatar asked Jan 11 '19 18:01

Joao Coelho


People also ask

What is output XML in Robot Framework?

Introduction. While Robot Framework is running tests, it generates an XML output file containing all information about the execution. After execution is over it creates, by default, log and report files using rebot tool internally.

What is Robot XML?

Robot Framework library for verifying and modifying XML documents. As the name implies, XML is a library for verifying contents of XML files. In practice, it is a pretty thin wrapper on top of Python's ElementTree XML API.

How do I read a text file in Robot Framework?

You can use the keyword Get File from the OperatingSystem library to read the file, and you can use the Split to Lines keyword from the String library to convert the file contents to a list of lines. Then it's just a matter of looping over the lines using a for loop.

How do you get text in robot framework?

You just have to identify the stop point, which in your example looks like it would be the hyphen between the two number values. for example: to extract the last five digits of this string ABC12345 you would want to create a variable to assign the text to.


1 Answers

Ok, found 3 viable responses:

  1. Use DbBot and query the DB created.
  2. Parse the XML file directly. Using xml.etree.ElementTree is pretty simple.
  3. Use Robot Framework's ExecutionResult, which follows the Visitor pattern (in ResultVisitor, which we have to extend) and that allows you to do what you need in the visit_test method.

Ended up with going with option 3 as that is part of Robot Framework and less likely to break (or easier to fix) if the format of the XML file changes.

like image 57
Joao Coelho Avatar answered Sep 22 '22 05:09

Joao Coelho