自动化工具 有谁知道如何在 testng report 中格式化显示 Json 吗

Polly · 2019年07月08日 · 最后由 对酒当歌 回复于 2019年07月09日 · 1300 次阅读

有谁知道如何在 testng report 中格式化显示 Json 吗?框架:Rest Assured+testng

共收到 1 条回复 时间 点赞

Allure 插入附件

@Attachment("请求报文")
    public static String requestBody(String URL, String body) {

        //格式化json串
        boolean prettyFormat = true; //格式化输出
        JSONObject jsonObject = JSONObject.parseObject(body);
        String str = JSONObject.toJSONString(jsonObject,prettyFormat);

        //报告展现请求报文
        return URL+"\n"+str;
    }

    @Attachment("响应报文")
    public static String respondBody(String respond) {
        //报告展现响应报文
        return respond;
    }

case 引用

// 请求
requestBody(SelfConfig.onlineurl + url,jsonObj.toString());


// 响应      
String json = response.asString();
System.out.println("json:  "+json);
JsonPath jp = new JsonPath(json);

//测试报告展现 请求报文
respondBody(json);

报告展示

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册