testng-team/testng

While creating a custom code for html table in emailablereport.html, Multiple <br> tags are getting added

Closed this issue · 4 comments

TestNG Version

Note: only the latest version is supported
7.10.2

Expected behavior

Should not add
tag, until explicitly mentioned in the Reporter Log

Actual behavior

While creating a custom code for table in emailablereport, Multiple
tags are getting added

Is the issue reproducible on runner?

  • Shell
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • IntelliJ
  • NetBeans

Test case sample

Please, share the test case (as small as possible) which shows the issue

image

image

image

Contribution guidelines

Incase you plan to raise a pull request to fix this issue, please make sure you refer our Contributing section for detailed set of steps.

@jayshreekant - It's not clear what the issue is. Can you please help share a sample project that can be used to reproduce the problem? If the issue is with the default TestNG reporters that come bundled with TestNG, then maybe you could mention the report name and/or the listener class from wherein you think this discrepancy is popping up.

Hi, @jayshreekant.
We need more information to reproduce the issue.

Please help share a Minimal, Reproducible Example that can be used to recreate the issue.

In addition to sharing a sample, please also add the following details:

  • TestNG version being used.
  • JDK version being used.
  • How was the test run (IDE/Build Tools)?
  • How does your build file (pom.xml | build.gradle | build.gradle.kts) look like ?

It would be better if you could share a sample project that can be directly used to reproduce the problem.
Reply to this issue when all information is provided, thank you.

@krmahadevan Kindly execute this code using mvn clean test

DemoMavenProject.zip

and Iterate to \DemoMavenProject\target\surefire-reports\emailable-report.html

and check how many <br> tag has been added in the table. because of this report is looking so bad and user have to scroll down many times to see the table section

image

@jayshreekant - The problem lies in your test code. You are basically trying to construct a html table using a series of Reporter.log() messages. I believe this is what skews up the entire html report.

The Emailable HTML Report was never meant for such sophisticated usecases I believe. You should ideally speaking be building your own reporting solutions.

All said and done, the below altered sample test code will ensure that the problem goes away. The code that I am sharing below basically constructs the entire html table as a single string and dumps it as 1 log message (instead of doing it as n log messages which your sample was doing)

import org.testng.Reporter;
import org.testng.annotations.Test;

public class ErrorLotOfBreak {
    @Test
    public void ErrorLotofBreak() {

        Reporter.log("Sample Text 1");
        Reporter.log("Sample Text 2");
        Reporter.log("Sample Text 3");
        Reporter.log("Sample Text 4");
        Reporter.log("Sample Text 5");
        Reporter.log(buildTable());
    }

    private static String buildTable() {
        return "<table><th>Age/Priority</th><th>URL</th><th>Count ()</th><th>Status</th>" +
                "<tr>" +
                "<td>" + "Ram" + "</td>" +
                "<td>" + "Shyam" + "</td>" +
                "<td>" + "Dheeraj" + "</td>" +
                "<td>" + " Alert " + "</td>" +
                "</tr>" +
                "<tr>" +
                "<td>" + "Ram" + "</td>" +
                "<td>" + "Shyam" + "</td>" +
                "<td>" + "Dheeraj" + "</td>" +
                "<td>" + " Alert " + "</td>" +
                "</tr>" +
                "<tr>" +
                "<td>" + "Ram" + "</td>" +
                "<td>" + "Shyam" + "</td>" +
                "<td>" + "Dheeraj" + "</td>" +
                "<td>" + " Alert " + "</td>" +
                "</tr>" +
                "<tr>" +
                "<td>" + "Ram" + "</td>" +
                "<td>" + "Shyam" + "</td>" +
                "<td>" + "Dheeraj" + "</td>" +
                "<td>" + " Alert " + "</td>" +
                "</tr>" +
                "<tr>" +
                "<td>" + "Ram" + "</td>" +
                "<td>" + "Shyam" + "</td>" +
                "<td>" + "Dheeraj" + "</td>" +
                "<td>" + " Alert " + "</td>" +
                "</tr>" +
                "</table>";
    }
}
image

Am closing this issue as question answered, since there's not much that can be done from TestNG side in this case.