-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support JSON output files as part of execution #3423
Comments
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 |
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 |
The are two design decisions to be made:
|
There is also another option to reduce output size: write directly to tar.gz. |
https://docs.python.org/3/library/tarfile.html |
@mkorpela one reason why i am set on an json option is the possibilities of using NoSQL databases to easily store robotframework results. |
Can you @teaglebuilt explain how this feature would help storing results in a db? |
@pekkaklarck 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 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 |
STATUS UPDATE: working on JSONELEMENTHANDLER, rebot accepting endswith(.json) on output file.... |
|
@teaglebuilt could you share the JSON format you're looking to produce? 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 So few things come to mind:
I was looking at this for JSON structure and JSON to python objects:
Also, please let me know if i can help. |
So I've taken a fork and created a JSON Schema and added a "--json" option to rebot so you can convert your XML results into JSON. There are a couple of things which I have done which are probably not consistent with robot.
I appreciate that it's been said that this could be done as part of the robot output. I don't think it'd be hard to adapt what I've done to that. Having said that though, I figured that rather than attaching the JSON to the robot implementation it was better as rebot. If you want the format in something else (i.e: Xunit) you simply use rebot to fix it up. I'm quite new to github, and haven't done any contribution before now. So there maybe some rules which I'm not so aware of, so if I'm doing something stupid please let me know. |
Quick comments:
|
Okay, so I have updated my code. Robot will now output a .json file.
Should I open a pull request so you can track the changes, as I'm also renaming some functions (so robot can remain agnostic to what output format is chosen). |
Another update, rebot is now able to accept the .json format as an input. This allows it to combine with either other XML files, or other JSON files. It can produce either XML output, or JSON output. I've tested it against a couple of examples so far and it seems to work fine.
|
Sounds great! Quick comments from me again:
|
Ping @Muusssi! |
Unfortunately I haven't found the time to progress this forward more.
|
I like the idea to generate output in json format . i have similarly situation where i want output in json format so that i can upload test result in other external tracking system. May i request you to please update the RF3.2 release date. |
RF 3.2 will be released very soon. This issue needs to wait for future versions. |
I've been looking at this again today, I've updated it so the unit tests pass, but I'm suffering from encoding issues with strings for acceptance testing. |
Sorry it's been so long since my last update. COVID-19 has only made me more busy (as I imagine it has many software engineers). I've come back and had a look at my code and realised it was left in a bit of a state (it would produce various different errors, and wasn't properly forming the models with the element handlers). I've resolved these issues and I have been running some tests with rebot and found that I can convert freely between XML and JSON using rebot, and that the data trasformation between the two is consistent!! (Hooray) I have also ensured that the output from the JSON validates against the schema! (Hooray again). I have also done some testing with timings, although these have been very limited tests. I was noticing, with a fairly basic robot file, that XML was marginally quicker. XML: 0.033s I don't know if this changes with larger robot files. I imagine this might change based off of the kind of hard disk you have available (I have an NVMe SSD) as the JSON implementation will store the results in memory and will write to disk when it's complete, rather than the XML implementation which looks like it writes to disk as it goes. This implementation is unfortunate as it makes the JSON implementation harder to do with the visitor pattern because you have to remember "where you are" between visits. I'm increasingly finding that my implementation of the JSON is stable, but the other surrounding bits (like recognising the output file ends in ".json", and the addition of the "--json") don't quite work how I'd expect them to. So my next task is to ensure that the flows are working how I'd expect them to be. Afterwards I'll look to implement the other options that rebot supplies as it looks like some of the options around flattening are completed when the XML is loaded and is something I'll have to in the loading of the JSON. All in all, seems to be coming along nicely! I have two questions. In my pull request, I'm getting some failures that I wouldn't expect to be getting based off of the code I've changed. Are there known issues with the existing set of acceptance tests, or have I done something wrong (such that I'd be getting failures with the help lines)? I'm getting failures in Python2 acceptance tests because there are a whole load of string classes robot has for dealing with unicode strings in Python2 and this grinds against my implementation. For recognition of the output ending in ".json" I have implemented a line of code like so: Edit: Third question. Has anyone had the time to look over the JSON schema? I think it's good and reflects what I'd expect robot to look like in JSON, but obviously this is an important part of the implementation. |
I've just run an example on my laptop (with a SATA SSD). This is across 20 runs of the same robot script: JSON = 3.6550284 My laptop has slower specs, but I think the notable difference is that it has a SATA SSD rather than an NVMe drive which benefits the performance of the JSON implementation. This is the example robot file (simple): https://gist.github.com/Lemonlemmings/c6b33ea88e68327cc63afd5c6c793f26 Since it's been a while here is the outputted JSON from that run: https://gist.github.com/Lemonlemmings/cc92e26f3edd02ae40d700352ef63e77 |
Thank you for adding this feature , and expecting it to be released soon as I got a requirement to have the output.xml converted to output.json, Actually I'm trying to develop the code for this conversion and facing difficulties and when I googled for solution I ended up in this link and happy to see such feature is being added, Expecting the release soon and have to thank and Congratulate this team for the good effort, Great work guys..! |
Let's see can we get this done already in RF 7.2. As mentioned above, the result model can nowadays be serialized to JSON and Rebot also supports JSON outputs, so we don't need to discuss about the suite structure anymore. We need to define the higher level result structure, but that's covered by #5160 that's already in RF 7.2 scope. The remaining task related to this issue is creating a logger that can write JSON incrementally. Also that has challenges like taking flattening into account, but I don't expect it to be too complicated. |
Most important changes: - Introduce new `LogLevel` object with `is_logged` method to replace the old callable `IsLogged`. The new `is_logged` accepts a `Message`, not a level, and also checks is its `message` set to `None`. - Share same `LogLevel` object with all loggers that want to follow the normal log level. This eases setting it during execution. - Move checking is a message logged away from the low level `XmlLogger` to higher level `XmlLoggerAdapter`. This is the first step of making `XmlLogger` as simple as possible and moving its generic logic to higher level. This will simplify adding the planned `JsonLogger` considerably (#3423).
Motivation is making `XmlLogger` as simple as possible by moving its generic logic to higher level. This will simplify adding the planned `JsonLogger` considerably (#3423). Logic that's moved: - Flattening. - Handing errors.
Also move it to its own module from `xmllogger`. In the future `OutputFile` will handle also JSON logging (#3423).
Implementation ready and tested with unit tests. To do: - Acceptance tests including schema validation. - Handling keywords executed by listeners in random places. - Documentation.
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 |
Will be used for testing JSON results during execution (#3423).
Also enhance tests for JSON output with Rebot.
Listeners logging or running keywords in strange places cause unexpected data to be logged. Make sure such data is handled correctly also when using JSON output (#3423). The exact output isn't tested as thoroughly as with XML. It is more important to make sure that tests are executed as expected and outputs aren't corrupted.
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. |
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:
The text was updated successfully, but these errors were encountered: