Search code examples
javaseleniumextentreports

Java and ExtentReport : how to add New line in JSON format


I have several fields that i parse from HTML page and add into my report:

extentTest.log(Status.INFO, String.format(
                "Add new record into database (%s)",
                "{\n" +
                        "   Name = name, \n".replace("name", name) +
                        "   Description = description, \n".replace("description", description) +
                        "   Language = language, \n".replace("language", language) +
                        "   Time = time, \n".replace("time", time) +
                        "}"));

So instead of see this in my HTML report with this kind of format:

Document{{
   Name = 5967745223993a32646baab8, 
   Description = "bla bla, 
   Language = en,
   Time = "2534
}}

is see in like this (without new lines):

Document{{ Name = 5967745223993a32646baab8, Description = MongoDB, Language = en, Time = "2534 }}

Any suggestions ?


Solution

  • Instead of "\n" you need to use <br /> tag for Extent report new line,

    extentTest.log(Status.INFO, String.format(
                    "Add new record into database (%s)","{<br />" +
                            "   Name = name, <br />".replace("name", name) +
                            "   Description = description, <br />".replace("description", description) +
                            "   Language = language, <br />".replace("language", language) +
                            "   Time = time, <br />".replace("time", time) +
                            "}"));