extentreports-java icon indicating copy to clipboard operation
extentreports-java copied to clipboard

MarkupHelper.createCodeBlock((json, CodeLanguage.JSON)) adding invalid "-"'s to the output

Open adamh109 opened this issue 3 years ago • 2 comments

Hi,

Summary: When making calls to log formatted JSON messages to an execution report, it's been adding unexpected "-"'s to the logged messages in some cases. This might be how's empty arrays are being interpreted ? I've put the example code and output below for reference. Is this a known issue or is there a JAVA based workaround for it at the moment ?

Many thanks.

Tool Info: From the project POM file: <groupId>tech.grasshopper</groupId> <artifactId>extentreports-cucumber6-adapter</artifactId> 2.13.0 test

NB: I've already contacted the makers of the higher-level plug-in (as I could see that question being asked straight away :-) ) but they weren't able to help further (a known feature with Extent Reports?) More specifically I'm using the plug-in at this point to simply expose the underlying Extent Reports method and using that directly.

Example Code: ExtentCucumberAdapter.getCurrentStep().info(“”); ExtentCucumberAdapter.getCurrentStep().info(“= From Extent Reports site”); String json = “{‘foo’ : ‘bar’, ‘foos’ : [‘b’,’a’,’r’], ‘bar’ : {‘foo’:’bar’, ‘bar’:false,’foobar’:1234}}”; ExtentCucumberAdapter.getCurrentStep().info(MarkupHelper.createCodeBlock(json, CodeLanguage.JSON)); ExtentCucumberAdapter.getCurrentStep().info(“”); String jsonTwo = “{\”@odata.context\”:\”URL\”,\”Id\”:null,\”IdTwo\”:\”12345\”,\”errors\”:[],\”warnings\”:[],\”information\”:[]}”; ExtentCucumberAdapter.getCurrentStep().info(“= Another one”); ExtentCucumberAdapter.getCurrentStep().info(MarkupHelper.createCodeBlock(jsonTwo, CodeLanguage.JSON)); ExtentCucumberAdapter.getCurrentStep().info(“****************************************”);

Generated Output:


= From Extent Reports site

{ – “foo”: “bar”, “foos”: [ – “b”, “a”, “r” ], “bar”: { – “foo”: “bar”, “bar”: false, “foobar”: 1234 } }


= Another one

{ – “@odata.context”: “URL”, “Id”: null, “IdTwo”: “12345”, “errors”: [ –

], “warnings”: [ –

], “information”: [ –

] }


Many thanks

adamh109 avatar Aug 01 '22 14:08 adamh109

This '-' is used for toggling the display. If you inspect the '-' element (span class='jstFold') in the browser, there is an onclick event JSONTree.toggle(). This does not seem to be working properly.

You can try to write a custom js in the spark config xml file, which hides this element from display. There is 'js' tag available in the xml for this purpose. Maybe this works for you.

grasshopper7 avatar Aug 02 '22 05:08 grasshopper7

Hi, Thanks for the prompt information, I've "unfortunately" been out of the office recently.

I had come at this issue from the angle of comparing the output to the one you get "regular pretty printing" of JSON messages in Java code, for instance using the GSON library setPrettyPrinting approach, so seeing the extra "-"'s was confusing initially. Plus, how the generated output couldn't be treated as a valid JSON message at that point as things like Postman would reject it I think. [Update: I've tried posting the generated output into some JSON message validators again today with some positive success (not 100%); plus when I paste it first into Notepad++ the "-"'s are removed so that helps.]

Agree, when I inspect the report I can see the onclick event you mention and how it isn't working right now. I'll try raising a new ticket for that issue and link it to this one.

@grasshopper7: On the custom JS front and updating the spark config XML file in the process, as I have no experience with custom JS code, do you know of any examples you could point me to showing how to do this and incorporating it into the spark config file ? Thanks in advance...

[NB: Then I might be able to work out if it's possible to get the actual Cucumber steps listed in the Extent report shown in Bold text as well (a custom requirement on my current commercial project)]

adamh109 avatar Aug 15 '22 16:08 adamh109