Skip to content

External parser API for custom parsers #1283

Closed
Closed

Description

@spooning

Originally submitted to Google Code by jussi.vastimo on 21 Nov 2012

We have many test cases defined for different framework. test cases are defined via xml file.

I have made my own reader and added it to populators READERS dictionary. This works for me. Is it possible add this kind of parameter for Framework class?
from .xmlreader import XmlReader

READERS = {'html': HtmlReader, 'htm': HtmlReader, 'xhtml': HtmlReader,
'tsv': TsvReader , 'rst': RestReader, 'rest': RestReader,
'txt': TxtReader, 'xml': XmlReader}

Activity

  1. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @pekkaklarck on 21 Nov 2012

    I have been thinking about this kind of functionality earlier and actually proposed it in comments of issue 1189 . I think this could be implemented so that you could specify new parsers, and override existing, from the command line, for example, like --parser XML:XmlReader. Shouldn't be too complicated to implement. What do you think?

  2. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by jussi.vastimo on 22 Nov 2012

    Sounds good. New parser is appended to dictionary and override if there is key for that file extensions. Right?

  3. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @pekkaklarck on 26 Nov 2012

    Yep, new parser should be added to the dictionary and be used with the registered extensions. I would like all these features to be implemented:

    1. Register new parsers for new extensions (e.g. xml:XmlReader)
    2. Register existing parser for new extension (e.g. rhtm:HtmlReader)
    3. Register new parsers for existing extensions (e.g. html:MyParser)
    4. Disable existing parsers (e.g. html:NONE)
  4. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @pekkaklarck on 26 Nov 2012

    Jussi, is the XmlReader you have implemented generic? Would you be interested in releasing it as a separate project? That would make it more attractive for us to implement this feature. Possibly it could already be done in 2.7.6 along with related issue 1018 .

  5. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @pekkaklarck on 26 Nov 2012

    Issue 1189 has been merged into this issue.

  6. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by jussi.vastimo on 26 Nov 2012

    I'm afraid it is not generic.

  7. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @pekkaklarck on 3 Dec 2012

    Any change you could make it generic?

  8. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by jussi.vastimo on 3 Dec 2012

    here is my parser. As you can see content is not very generic. But perhaps you can use it as a reference or example.

  9. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by ChrisPrinos on 26 Feb 2014

    Attached is a patch to implement user defined parsers, generally following the scheme described in comment 3 above by Pekka.

    it provides a --parser command line option to specify an extension and class to handle the parsing, alowing reassignment of existing parsers to new extensions, or allowing new parsers to be added either for existing or new extensions. It does not allow disabling of a default parser, though that would not be hard to change.

    Changes in the patch include modifications to support the new cli option, documentation updates, and a set of acceptance tests.

    Diff is based on today's trunk.

  10. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by adadcall... on 27 Feb 2014

    Great timing. I have just started work on parsers for .docx and .xlsx files, using 3rd-party python libraries. I have a minimal-working example in a local clone of RF trunk, and about to start working on some test cases. So the patch above would make this much easier if you were not interested in merging these parsers into the main project. I could set these up as a separate project, with an independent set of test cases.

    I have some time to work on this further next week. If you are going to merge the cli patch soon, I will hold off further work until it is available for me to complete the development.

    Just also to say thanks for making RF so awesome. I have recently introduced it into a major new project in a global investment bank with great success ... time to release new software changes into production has come down from about 3 months to about a week, because we do almost all the testing using RF instead of hours of throwaway manual regression testing.

  11. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by ChrisPrinos on 27 Feb 2014

    here's a clone with the changes applied (in the issue-1283 branch)

    https://code.google.com/r/chrisprinos-robotframework-1283/source/browse?name=issue-1283

  12. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by adadcall... on 6 Mar 2014

    I have uploaded the first experimental version of a pair of parser modules for Microsoft .docx and .xlsx formatted files using this new patch:

    https://github.com/rjsmith/robot-ooxml

  13. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by bryan.oakley on 14 May 2014

    I really like the idea about being able to replace the built-in parser with a custom one I vote for this issue if it provides the ability to override built-in parsers for existing files (eg: use my own parser for .robot files).

  14. rjsmith commented on Mar 6, 2015

    @rjsmith

    Hi,
    Is there any prospect of this ever getting added to the robot framework core? The hard work has already been done for you by Chris Prinos ...... I would really find it useful so that I can run RF tests directly from Microsoft Office files (using my bolt-on docx and xlsx parser)

  15. pekkaklarck commented on Mar 6, 2015

    @pekkaklarck
    Member

    The situation with this is very much open. On one hand we can see that supporting new test data formats would be useful, but on the other hand they do add maintenance burden and can also limit syntax choices in the future.

    I would prefer alternative formats to be supported via an interface so that they could be developed independently similarly as test libraries, listeners and other tools. Obviously you can already now convert data in any format to format supported by Robot before running tests, but I would prefer it to be possible to use a programmatic API. Ideally you should be able to specify something like --dataparser xsl:ExcelParser to register a custom parser for .xsl files.

    A twist in this planning is that we have been thinking could we in RF 3.0 drop HTML test data support and support only the plain text format (+ TSV which is nearly 100% compatible with it). Having a way to register custom parsers would make that change less backwards-incompatible and thus more doable.

    Both supporting alternative parsers and possibly dropping built-in support for HTML format are something we need to ask community opinion about. Sending an email about the latter to robotframework-users is already on my to-do-after-RF-2.9-alpha-1 list and I can ask opinions about the former at the same time. We obviously can continue discussion here already before that.

  16. 49 remaining items

  17. pekkaklarck commented on Apr 27, 2023

    @pekkaklarck
    Member

    The new parser API has now been documented and there have also been few smallish enhancements. I consider this issue done. Testing and all kind of comments are highly appreciated!

  18. changed the title [-]Possibility to use custom parser for test data[/-] [+]External parser API for custom parsers[/+] on May 5, 2023
  19. pekkaklarck commented on May 9, 2023

    @pekkaklarck
    Member

    @d-biehl commented on Slack that it would be good if the parser API supported multi-part extensions like .feature.md. That's a good idea so I'll add that support still. It's not trivial but shouldn't be overly complicated. Thanks for testing and feedback!

  20. added 2 commits that reference this issue on May 9, 2023
  21. pekkaklarck commented on May 9, 2023

    @pekkaklarck
    Member

    Done! I also enhanced TestSuite.name_from_source so that it can handle paths with multipart extensions.

    I can imagine that there could be preprocessors that support files like tests.robot.md. They only needed to parse Robot data from files and pass it to TestSuite.from_string.

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