-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Support serializing executable suite into JSON #3902
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
Comments
I propose we add We should also add We probably should add |
Serializing a big suite into JSON is problematic because reading it back requires deserializing the big JSON string first. To avoid problems with that, I propose we support splitting suites into multiple objects using this algorithm:
I propose we support both "one big object" and "split object" formats when construction model objects using An example of a suite as one object:
Same suite split to multiple objects:
Body items need a type to separate normal keywords from setups and teardowns as well as from IFs and FORs. We probably could omit the type with normal keywords (the common case) to make the file size smaller. Above examples use spaces between items but I believe we should omit them to reduce file size. UPDATE: Setups and teardowns are nowadays stored in model objects outside the
We probably needed to separate keywords from control structures such as UPDATE 2: Splitting JSON like this won't be implemented as part of RF 6.1 where the JSON serialization will be introduced. We can return to this later if/when there are need. UPDATE 3: It seems that Newline Delimited JSON is gone ( |
I propose we use new We should allow running We should have a way to convert a file or a directory into a
UPDATE: RF 6.1 will support |
Saved suite objects in |
External resource files could possibly be saved into a |
This issue is highly related to the proposal to add JSON based output format (#3423). Executable suite structure and result suite structure are similar, they even have common base, and they should use the same approach to serialize them to JSON. I think splitting a suite into multiple objects like I propose above ought to work fine also with result suites. They couldn't use the proposed .rbt extension, though, because they contain different data and we don't want |
The biggest reason to split JSON into multiple objects is to avoid the need to read the whole file into memory and parse the whole JSON in one go. This may not be a huge problem with data, but if this same approach is used with results (#3423) it's very important because I've seen output.xml files that are over 1GB. Assuming we have this JSON from the earlier example
it could be processed like this:
We could extend this mechanism to strings so remove duplication. For example, the first line of the above example could be changed to this:
This way if we ever need to use string "Suite" again, we just use We use similar approach, created years ago by @mkorpela and @jussimalinen, to remove duplication in log.html and report.html and there it has worked great. There we also zip long strings but I'm not sure is that needed here. It's easier and probably better to zip the whole file when needed instead. There we also represent all timestamps as integers representing milliseconds as a difference to a base time set only once. That means that instead of using e.g. |
Too big task for RF 4.1. Hopefully can be included in RF 5.0. |
Were you @mkorpela and @Snooz82, or someone else, working with something that would benefit from this feature? If yes, we need to make sure this makes it into RF 5.0. We could start with a design discussion session on Slack sometime soon. If nobody needs this in the near future, it might ne better to postpone this to RF 5.1 to ensure we get RF 5.0 out in time. Either way, I consider this an important enhancement and want to see it land reasonably soon. |
Using TestSuiteBuilder, i have been able to generate json from existing testsuite. It would be nice to have the whole testsuites stored to json object prior to running or post running of the complete suite to build a complete "object hierarchy". Further more, examples for model transformation CRUD operations should be present in the documentation. TestSuite helps us create new testcases dynamically, why not give complete example demos of them for users to explore and also a possibility to save TestSuite as ".robot" or json format again for reusability in future. |
@pekkaklarck I had an idea at one point to built a reporting package to npm and JS/node world that could take current format js arrays + logic of log html in and give the package user opportunity to use the format. |
Wishing list as a robotframework/RPA development
|
Another item i missed out is
|
@awasekhirni, this issue covers most of the features you want. Somehow including also referenced resource and variable files or even libraries is out of its scope. Once this issue is done, we can look at those enhancements as well. |
I've been lately thinking this issue a bit because we could possibly use the same underlying logic to convert model objects to dictionaries (that can then later trivially be converted to JSON) could possibly also used elsewhere. For legacy reasons there's still code that considers everything tests contains keywords although there can be FOR loops, IF/ELSE structures, and after RF 5.0 also RETURN, BREAK, CONTINUE, and TRY/EXCEPT objects. The current non-keyword objects have attributes that allow using them as keywords, but that requires quite a bit of code here and there and is ugly in general. I want this compatibility code to be removed sooner rather than later, but there still should be a way to somehow uniformly operate all "body items" tests can contain. A solution I've been thinking is adding method If the aforementioned UPDATE: Data side objects ( |
At the moment it seems unlikely this issue will make it to RF 5.0. There are other more important issues and when they are done we probably want to create the release so that we get them into real use. |
- Support loading JSON using open file or file path. - Support serializing to open file or file path. - Customizable JSON formatting. Defaults differ from what ``json`` uses by default.
This is the most important RF 6.1 issue because there are so many interesting usages for it in the ecosystem. Basic functionality is ready and will be part of the forthcoming RF 6.1 alpha 1. This is what works:
|
Remaining tasks to get this done:
Anything else that's still missing? Any opinions about handling resource files? Ping especially @manykarim. |
I know it might be a bit late now, but perhaps once model is loaded from JSON (*.rbt), one could update its variable with e.g. model = TestSuite().from_json()
model.update_variable(var="myvar", value=15)
model.update_variable(var="listvar", value=["Bill", 0, None])
# it updates model body, but one can imagine that saved ROBOT would look like below
# ***SETTINGS***
# ${myvar} ${15}
# @{names} Bill ${0} ${None} As I remember, variables are stored as |
You can manipulate |
- Add typing. Part of #4570. - Enhance `config` to convert values to tuples if original attribute is a tuple. This preserves tuples returned from `to_dict` in `to_json/from_json` roundtrip (#3902). Alternative would be using `@setter` with all attributes containing tuples, but it's easier to handle them here. - Enhance `config` to require attributes to exist. This enhances error reporting.
- Add type hints. Part of #4570. - Make attributes containing normal sequences (i.e. not our custom objects like Tags) explicitly tuples in `__init__`. - Perserve tuples as tuples, instead of converting to lists, also in `to_dict` (related to #3902). That means less work and smaller memory usage. Earlier change to `ModelObject.config` makes sure tuples are preserved over `to_json/from_json` roundtrip. - Use tuples attributes also with `robot.running.model.UserKeyword`. That module will get types and be enhanced in the near future.
- Support JSON resource files. Possible extensions are `.json` and `.rsrc`. - Handle failures in parsing JSON files gracefully. - Tests.
The above commit added support for JSON resource files and enhanced error handling if a parsed JSON file is invalid. With resource files it is possible to use either |
There are currently the following limitations:
The limitations listed above above need to mentioned in the documentation. |
Also enhance the Selecting files to parse section in general. The section now covers also `.json` and `.rbt` extensions even though the JSON format (#3902) isn't otherwise documented yet.
Makes it possible to make suite source relative and to add a custom root to it. This is especially useful when moving data around as JSON (#3902). Also add docstring to `Metadata`.
In the previous comment I mentioned that absolute suite source is problematic. The commit above added from robot.running import TestSuite
# Create a suite, adjust source and convert to JSON.
suite = TestSuite.from_file_system('/path/to/data')
suite.adjust_source(relative_to='/path/to')
suite.to_json('data.json')
# Recreate suite elsewhere and adjust source accordingly.
suite = TestSuite.from_json('data.json')
suite.adjust_source(root='/new/path/to') After this enhancement, I consider JSON serialization support to be good enough for RF 6.1. Documentation is still missing, but I'll write it after the first release candidate is out. |
Also minor changes to the JSON model itself. Most importatnly, fix `While` to include `on_limit`.
Includes: - Using JSON suite files. - Using JSON resource files. - Using reST resource files. - Recommend `.resource` with normal resource files more strongly. - List all supported extensions under Registrations. Also document reST resource files.
Commits listed above have added a JSON schema as well as documentation in the User Guide. Creating JSON resource files was made more convenient by #4793. We can finally consider this issue done. |
It would be convenient to be able to serialize executable
TestSuite
objects into JSON that can be then also be used to recreate same suite later. Most important use cases are:In the subsequent comments I'll go through some design ideas I have related to this. Please use 👍 and 👎 to indicate do you like those ideas as well as this issue in general. Written comments obviously appreciated as well!
The text was updated successfully, but these errors were encountered: