Skip to content

Support JSON output files as part of execution #3423

Closed

Description

@teaglebuilt

Problem:

Prefer to use a NOSQL database to store test reports. NOSQL databases typically require json format because its a relational database.

Solution:

Provide robotframework with the ability to use json rather than xml in the output file.

For example:

           # flag --output
          robot --output output.json ./tests

Activity

  1. teaglebuilt commented on Dec 21, 2019

    @teaglebuilt
    Author

    If its ok with the community, I would like to work on this. I created a pull request for tracking progress and questions along the way

  2. pekkaklarck commented on Dec 21, 2019

    @pekkaklarck
    Member

    Being able to use output.json instead of output.xml may be useful. Biggest possible benefits I see are:

    • JSON is a lot less verbose than XML, so output.json file would be a lot smaller than output.xml.
    • Because output.json would be smaller, writing it to disk during execution would be faster as well.
    • It is possible that processing output.json would be faster than processing output.xml. This is not certain, though, as our XML processing code is pretty well optimized and the underlying XML modules are pretty fast.

    If processing output.json is faster than processing output.xml, then this feature is definitely a good idea. If it isn't, then we need to think are the other benefits big enough. This is something we can only know after prototyping this a bit.

    I don't thing possibility to add data to a NOSQL database or to any other system is a good reason to add anything like this. It is already now possible to do that by parsing the information from output.xml using the standard XML modules or the robot.api.ExecutionResult API. Data being stored in JSON instead of XML doesn't really make a big difference.

  3. pekkaklarck commented on Dec 21, 2019

    @pekkaklarck
    Member

    The are two design decisions to be made:

    1. How to enable this feature. I don't think any new command line option is needed. We just need to make it possible to say --output output.json and detect the type automatically. Also Rebot needs to be enhanced to allow using rebot output.json.

    2. The output.json format. Because it would be a new external interface, it needs to be designed carefully. No need to think about that too much in the beginning, though. It is more important to test are there performance benefits or not. If there are, then we need to design the format more carefully.

  4. changed the title [-]Create output.json option in reporting for json formatted reports[/-] [+]Possibility to use output.json in addition to output.xml[/+] on Dec 21, 2019
  5. mkorpela commented on Dec 22, 2019

    @mkorpela
    Member

    There is also another option to reduce output size: write directly to tar.gz.
    I think both reading and writing of output.xml would be fairly easy to modify to also being able to read and write (the same xml) to output.tar.gz

  6. teaglebuilt commented on Dec 23, 2019

    @teaglebuilt
    Author

    @mkorpela one reason why i am set on an json option is the possibilities of using NoSQL databases to easily store robotframework results.

  7. pekkaklarck commented on Dec 23, 2019

    @pekkaklarck
    Member

    Can you @teaglebuilt explain how this feature would help storing results in a db?

  8. teaglebuilt commented on Dec 24, 2019

    @teaglebuilt
    Author

    @pekkaklarck
    JSON is the query language used in NOSQL databases.

    Well, MongoDB for example, is technically BSON format which is relative to JSON. from what ive seen there are many complications to storing xml in a NOSQL database. These are some examples below,

    Mongodb
    Cassandra
    Couch DB

    They all require xml to be converted into JSON for storage. Unless you want to just save as a string which would not be able to query

  9. teaglebuilt commented on Dec 24, 2019

    @teaglebuilt
    Author

    @pekkaklarck with the possibility of output.json, we could essentially use NoSQL databases to store and query results. Then look into other possibilities of filtering and searching specific queries relative to the data in the output file

  10. teaglebuilt commented on Dec 29, 2019

    @teaglebuilt
    Author

    STATUS UPDATE: working on JSONELEMENTHANDLER, rebot accepting endswith(.json) on output file....

  11. pekkaklarck commented on Dec 29, 2019

    @pekkaklarck
    Member
    1. I still don't understand how Robot producing json output itself helps using any db. It is already now easy to read information from output.xml and write it to a db (or to a json file). If you have a db that accepts Robot's output.json as-is, then you avoid one step between test run and storing info to the db. Is that your motivation?

    2. Great that you have some progress!

    3. Have you already thought about the json format?

  12. sdave2 commented on Jan 7, 2020

    @sdave2

    @teaglebuilt could you share the JSON format you're looking to produce?
    I am also under a similar situation where I want to get the output as JSON format.

    Parsing XML and converting that to JSON I found to be very quick and also the XML gets converted into python objects and then I can use it like suite.suites and so on.

    So few things come to mind:

    1. Can you share the JSON structure you're looking to output

    2. Also, when I read the JSON output back into python for further processing, will it be converted into python objects?

    I was looking at this for JSON structure and JSON to python objects:

    1. https://json-schema.org/understanding-json-schema/
    2. https://pypi.org/project/python-jsonschema-objects/0.0.13/

    Also, please let me know if i can help.

  13. 58 remaining items

  14. pekkaklarck commented on Dec 12, 2024

    @pekkaklarck
    Member

    This is now mostly ready and thoroughly unit tested. Things to do:

    • Acceptance tests including schema validation.
    • Handling keywords executed by listeners in random places.
    • Documentation.

    Implementation turned out to be pretty complicated due to JSON syntax annoyances (trailing commas not being allowed required keeping state) and Robot's internal logging not supporting this style too well (for example, when a test starts, we need to make sure to add "tests":[ if it isn't added already and thus we need to keep more state). I'm happy how the code looks in the end, but getting it to this state took some time.

  15. pekkaklarck commented on Dec 18, 2024

    @pekkaklarck
    Member

    After the latest changes this feature is now done and ready to be released as part of RF 7.2 beta 1. Implementing this properly was a bigger task than I anticipated, so hopefully the functionality is useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions