prashant-ramcharan / courgette-jvm

Multiprocess | Parallel Cucumber-JVM | Parallelize your Java Cucumber tests on a feature level or on a scenario level.
MIT License
130 stars 38 forks source link

How to attach xml to Courgette-report #344

Closed SundarHubTest closed 1 year ago

SundarHubTest commented 1 year ago

I am trying to convert "XML" to byteArray and attach the same to Courgette-report ( like we attach image screenshot ). But I am not able achieve it. I have tried all the below option. Please have a look and guide us.

//method to convert the xml file to byteArray : public static byte[] writeXMLasByteArray(File xml) { byte[] byteArr = new byte[0]; try { byteArr = FileUtils.readFileToByteArray(xml); } catch (IOException e) { System.out.println("Exception thrown"); } return byteArr; }

//method to attach the (converted xml to byteAttary) to the courgette-report using "Scenario.attach(byteArray,mediatype,name) scenario.attach(writeXMLasByteArray(xml), "application/xml", "RequestXML"); - No error still, the xml not shown up in report scenario.attach(writeXMLasByteArray(xml), "charset=utf-8", "RequestXML"); - No error still, the xml not shown up in report scenario.attach(writeXMLasByteArray(xml), "text/xml", "RequestXML"); - No error still, the xml not shown up in report scenario.attach(writeXMLasByteArray(xml), "text/html", "RequestXML"); - No error and I able to see all XML values alone in the report.

I am expecting a link as "RequestXML" in the report, when i click, the full xml should display.

prashant-ramcharan commented 1 year ago

text/xml works fine and shows in the Cucumber report.

Currently, this will not show in the Courgette html report because only image/png and text/html are supported. I will have to update the code to also include text/xml

Example:

        String xml = "<courgette>\n" +
                "<heading>Courgette-JVM</heading>\n" +
                "<body>Attach this XML to the Cucumber report</body>\n" +
                "</courgette>";

        scenario.attach(xml, "text/xml", scenario.getName());

Cucumber report Screenshot 2022-07-25 at 13 00 06

prashant-ramcharan commented 1 year ago

I will include this in the next release.

SundarHubTest commented 1 year ago

Thank you for the Quick response. Let me wait for the new release, with the above changes incorporated. Thanks.

prashant-ramcharan commented 1 year ago

This is now released in Courgette 6.6.0.

You should be able to see the xml embedded in the Courgette html report.

Note that you will see the full xml in the Courgette report modal and not within a link. This is similar to the way in which xml is rendered in Cucumber reports.