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

JSON Archive breaks after first Test

Open realulim opened this issue 4 years ago • 3 comments

When using the ExtentSparkReporter and the JsonFormatter to create a JSON archive, so tests from subsequent test runs can be appended to the report, the following bug appears:

All text from report items with a screenshot disappear from the first test run.

Take a look at the enclosed screenshot. It shows the JSON archive after the first run (left) diffed against the JSON archive after the second run (right). As you can see the text "Text with Screenshot" has been deleted from the first report. Interestingly, the "Text without Screenshot" was retained.

screenshot

I tried to write a test for this bug, but ultimately couldn't get the checked out code to compile in my IDE (Netbeans). I will include the bare bones of my test. It has no Asserts, but it will produce the faulty JSON archive:

    @Test
    public void appendWithSparkReporter() throws IOException {
        for (int i = 0; i < 2; i++) {
            String reportPath = "target/append/index.html";
            String jsonPath = "target/append/index.json";
            ExtentSparkReporter sparkReporter = new ExtentSparkReporter(reportPath);
            JsonFormatter jsonReporter = new JsonFormatter(jsonPath);
            ExtentReports extent = new ExtentReports();
            extent.createDomainFromJsonArchive(jsonPath);
            extent.attachReporter(jsonReporter, sparkReporter);
            Media screenshot = MediaEntityBuilder.createScreenCaptureFromPath("img.png").build();
            ExtentTest test = extent.createTest("Testname1", "description1")
                    .log(Status.INFO, "Text without Screenshot", null, null)
                    .log(Status.INFO, "Text with Screenshot", null, screenshot);
            extent.flush();
        }
        // TODO write Asserts to show that "Text with Screenshot" from the first test run is still present.
    }

realulim avatar Dec 08 '21 17:12 realulim

Ok, I have gotten my IDE to behave somewhat, so here's a complete test showing the bug:

    @Test
    public void appendWithSparkReporter() throws IOException {
        ExtentReports extent = new ExtentReports();
        String textWithoutScreenshot = "Just some random text";
        String textWithScreenshot = "Some text explaining the screenshot";
        for (int i = 1; i < 3; i++) {
            String reportPath = "target/append/index.html";
            String jsonPath = "target/append/index.json";
            ExtentSparkReporter sparkReporter = new ExtentSparkReporter(reportPath);
            JsonFormatter jsonReporter = new JsonFormatter(jsonPath);
            extent.createDomainFromJsonArchive(jsonPath);
            extent.attachReporter(jsonReporter, sparkReporter);
            Media screenshot = MediaEntityBuilder.createScreenCaptureFromPath("img.png").build();
            ExtentTest test = extent.createTest("Append Test " + i, "Test Description " + i)
                    .log(Status.INFO, textWithoutScreenshot, null, null)
                    .log(Status.INFO, textWithScreenshot, null, screenshot);
            extent.flush();
        }
        for (com.aventstack.extentreports.model.Test test : extent.getReport().getTestList()) {
            if (test.getName().startsWith("Append Test ")) {
                for (Log logEntry : test.getLogs()) {
                    Assert.assertEquals(Status.INFO, logEntry.getStatus());
                    String details = logEntry.getDetails();
                    if (logEntry.getMedia() != null) Assert.assertEquals(details, textWithScreenshot);
                    else Assert.assertEquals(details, textWithoutScreenshot);
                }
            }
        }
        
    }

realulim avatar Dec 09 '21 16:12 realulim

I have a fix for this bug including a test that verifies it. But I could not open a Pull Request. Is anyone interested in receiving this contribution or should I fork and create my own release?

realulim avatar Dec 17 '21 12:12 realulim

Looks like this project is dead. I have forked the repo and fixed the bug: https://github.com/realulim/extentreports-java

realulim avatar Dec 20 '21 13:12 realulim