You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support JSON output files as part of execution #3423
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.
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.
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.
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
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
@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
@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
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?
@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:
Can you share the JSON structure you're looking to output
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:
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.
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.
Activity
teaglebuilt commentedon Dec 21, 2019
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
pekkaklarck commentedon Dec 21, 2019
Being able to use output.json instead of output.xml may be useful. Biggest possible benefits I see are:
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.ExecutionResultAPI. Data being stored in JSON instead of XML doesn't really make a big difference.pekkaklarck commentedon Dec 21, 2019
The are two design decisions to be made:
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.jsonand detect the type automatically. Also Rebot needs to be enhanced to allow usingrebot output.json.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.
[-]Create output.json option in reporting for json formatted reports[/-][+]Possibility to use output.json in addition to output.xml[/+]mkorpela commentedon Dec 22, 2019
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
mkorpela commentedon Dec 22, 2019
https://docs.python.org/3/library/tarfile.html
(Zip and others also could work)
teaglebuilt commentedon Dec 23, 2019
@mkorpela one reason why i am set on an json option is the possibilities of using NoSQL databases to easily store robotframework results.
pekkaklarck commentedon Dec 23, 2019
Can you @teaglebuilt explain how this feature would help storing results in a db?
teaglebuilt commentedon Dec 24, 2019
@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
teaglebuilt commentedon Dec 24, 2019
@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
teaglebuilt commentedon Dec 29, 2019
STATUS UPDATE: working on JSONELEMENTHANDLER, rebot accepting endswith(.json) on output file....
pekkaklarck commentedon Dec 29, 2019
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?
Great that you have some progress!
Have you already thought about the json format?
sdave2 commentedon Jan 7, 2020
@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.suitesand so on.So few things come to mind:
Can you share the JSON structure you're looking to output
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:
Also, please let me know if i can help.
58 remaining items
Support JSON output files as part of execution (#3423)
pekkaklarck commentedon Dec 12, 2024
This is now mostly ready and thoroughly unit tested. Things to do:
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.Add GROUP support to JsonLogger.
Add test data file that tries to cover all syntax.
Acceptance tests for JSON output during execution (#3423)
Handle logging and keyword running listeners with JSON output.
Enhance (and test) writing stats with JsonLogger (#3423)
Document JSON output during execution (#3423)
pekkaklarck commentedon Dec 18, 2024
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.