Customize xUnit Properties

Hello,

I would like to add properties to the xUnit file that is output when using the -x flag. This would be analogous to the record_property and record_testsuite_property Fixtures in Pytest.

We would then be able to nestle properties underneath the testsuite and any individual testcase:

<properties>
    <property name="requirement_id" value="1" />
</properties>

The properties could come from tags on tests or something. Is there any way to do this in Robot Framework?

Thanks!
Tom

Request for `log_property` functionality for xunit writer · Issue #3944 · robotframework/robotframework · GitHub addresses this

Hi Tom,

I had a look over that issue request you linked and saw your? comments.

I hadn’t replied to this earlier because honestly I don’t know much about xunit, so I was hoping someone more knowledgable would reply, and no point me cluttering up the thread.

It seems the feature you want is not there (by the request to add it), that issue is only 22 days old, so there is a good chance none of the RF maintainers have had a chance to look at it, it is an open source project after all so you could add the feature if you have the ability and issue a pull request.

If you don’t feel you have the ability to update the RF code, or you need a solution quickly, rather than post processing the output.xml file as discussed in that issue, another option would be to create a listener file that could generate your xunit xml for you. The Listener interface functions end_suite and end_test probably have everything you need and so you probably only need to write a listener function for each of those, and maybe one for start_suite that simply creates your xunit xml file with an initial blank template.

I hope this was helpful,

Dave.

Hi Dave,

I appreciate the response. I had forgotten about the listener interface. That does seem like it could be a good approach to generating xunit files with custom properties. I will post this suggestion in the GitHub issue.

Thanks,
Tom

Hi Tom,

I was suggesting you write your own listener file rather than waiting for someone else to make the solution for you.

If you need help writing a listener file, i’m happy to guide you.

Dave.

I have written a prerebotmodifier before. I think that I understand the basics. Actually, the listener interface makes things even easier by providing the xunit_file method, which runs when an xunit file is ready. I experimented and found that this method is called after the xunit file has already been written. This framework should provide a pathway for anybody wanting to postprocess an xunit file. I plan to somehow save the data that I need via end_test to a class field then use it in xunit_file.

Hi Tom,

I didn’t even realise the listener interface had an xunit_file method, so now I learned something, thanks :+1:t3:

It seems you have a path forward which is great news.

Wishing you good luck and hopefully you get something that works well for you,

Dave.