extent-framework / extentreports-java

Extent Reporting Library, Java
http://extentreports.com
Apache License 2.0
226 stars 127 forks source link

Are nodes created at the end of a test? #140

Closed akshayamaldhure closed 4 years ago

akshayamaldhure commented 4 years ago

extentreports version: 4.1.3

I have a base test implementation in my test framework, but I'm doing all the Extent Reports related initialisation in a TestNG listener. I'm using an ExtentTestManager (like this) for accessing my Extent Report related objects throughout the project. Since nodes are good expandable and collapsible elements in Extent Reports, I'm trying to use them for logging the REST API call details (request and response details) in my tests. However, I have observed that all the nodes I create are populated at the end of a given test irrespective of the time at which they are created during a test. Is this expected?

Below is what my code looks like.

ExtentTest apiDetailsNode = extentTest.createNode("API call details");
apiDetailsNode.pass("Request URI: " + request.getURI());
apiDetailsNode.pass("Response status: " + response.getStatus());

Is there anything I can do to have the nodes populated in a test as per their creation time?

akshayamaldhure commented 4 years ago

To my surprise, I'm observing that my screenshots added using the addScreenCaptureFromPath() method are also getting shown towards the end of a test.

anshooarora commented 4 years ago

The order is always:

Test
-- Events/logs
-- Node
    -- Events/logs
         -- Screenshots (events)
    -- Screenshots (node)
Screenshots (test)

I believe you can use JS to change the positioning of screenshots but putting events and nodes chronologically is not possible. It can be marked as an enhancement.

akshayamaldhure commented 4 years ago

@anshooarora What is the practical use of nodes? Don't you think it would be confusing if the nodes and screenshots do not appear in chronological order in a test? Otherwise, how would the screenshot text get linked to the corresponding screenshot? How to use JS to change the positioning of screenshots? Also, if not nodes, what way would you suggest to log REST API calls in the report in a clean way?

anshooarora commented 4 years ago

That is one use case. However, nearly a complete majority use-case is BDD and TestNG - which have a clear hierarchy and it only makes sense to group Suites/Features, Classes/Tests/Scenarios etc. together.

It would help me understand what and how you are creating the hierarchy. I saw https://github.com/extent-framework/extentreports-java/issues/142 and it is something that is currently achieved out-of-box so I am now a little confused as to what the requirement is.

akshayamaldhure commented 4 years ago

@anshooarora My requirement is exactly what I've mentioned in #142 plus logging REST API calls in a node-like fashion that lets me expand/collapse the API call details. However, the chronological order is still a matter of concern for me from a readability perspective.

So the overall report structure would look like this.

Test
  - Step (expandable/collapsible, possibly using node)
    - step logs
    - API call details (request and response) (expandable/collapsible, possibly another node)

Does this make sense and is it achievable using Extent Reports in any way?

anshooarora commented 4 years ago

The above mentioned scenario is feasible and is in fact the default behavior.

extent.createTest("Test")
  .createNode("Step")
    .pass("A log")
    .createNode("API call details")
      .pass("request")
      .pass("response");

or:

ExtentTest test = extent.createTest("Test");
ExtentTest step = test.createNode("Step");
step.pass("A log");
ExtentTest apiCallDetails = step.createNode("API call details");
apiCallDetails.pass("request");
apiCallDetails.pass("response");

The above gives me:

image