Java和ExtentReport:如何以JSON格式添加新行

时间:2018-09-19 10:52:12

标签: java selenium extentreports

我有几个字段是从HTML页解析并添加到我的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) +
                        "}"));

因此,不要在我的HTML报告中以这种格式查看此内容:

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

是这样的(没有新行):

  

文档{{名称= 5967745223993a32646baab8,说明= MongoDB,   语言= zh,              时间=“ 2534}}

有什么建议吗?

1 个答案:

答案 0 :(得分:4)

您需要对范围报告新行使用<br />标记,而不是“ \ n”

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) +
                        "}"));