【问题标题】:Postman/Newman junit report customizationPostman/Newman junit 报表定制
【发布时间】:2017-12-06 21:53:21
【问题描述】:

我正在使用 postman 和 newman 执行自动化测试,并执行 JUnit 导出以便在 TFS 中利用它们。 但是,当我打开我的 .xml 报告时,失败指示如下:

-<failure type="AssertionFailure">
    -<![CDATA[Failed 1 times.]]>
</failure>

我想知道是否可以自定义“失败 1 次”。信息以便传递有关失败的更多相关数据(即 json 正文错误和描述)

谢谢

亚历山大

【问题讨论】:

    标签: junit postman newman


    【解决方案1】:

    好吧,我终于知道了如何进行(到目前为止,这不是一个干净的方法,但足以满足我的目的):

    我影响了文件C:\Users\&lt;myself&gt;\AppData\Roaming\npm\node_modules\newman\lib\reporters\junit\index.js

    请求的数据和响应可以从'executions'对象中恢复:

    stringExecutions = JSON.stringify(executions); //provide information about the arguments of the object "executions"

    由此我可以通过 json 解析此元素并提取我想要的内容来获取一般信息:

    jsonExecutions = JSON.parse(stringExecutions)
    jsonExecutions[0].response._details.code // gives me the http return code,
    jsonExecutions[0].response._details.name // gives me the status,
    jsonExecutions[0].response._details.detail //gives a bit more details
    

    错误数据(在测试用例/测试套件级别)可以从“err.error”对象中恢复:

    stringData = JSON.stringify(err.error); jsonData = JSON.parse(stringData);
    

    从中提取我需要的数据,即。

    jsonData.name // the error type
    jsonData.message // the error detail 
    jsonData.stacktrace // the error stack
    

    顺便说一句,在原始文件中,堆栈无法显示,因为error.err中没有'stack'参数(它被命名为'stacktrace')。

    最终失败数据(在测试步骤/测试用例级别)可以从“失败”对象中恢复:

    stringFailure = JSON.stringify(failures); jsonFailure = JSON.parse(stringFailure);
    

    我从中提取:

    jsonFailure[0].name // the failure type 
    jsonFailure[0].stack // the failure stack
    

    出于我的目的,我将来自 jsonExecutions 的响应详细信息添加到我的测试套件错误数据中,这在 XML 报告中比以前详细得多。

    如果有更清洁/更智能的方法来执行此操作,请随时告诉我,我将不胜感激

    下一步:通过创建自定义报告器进行清理。 :)

    亚历山大

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-17
      • 1970-01-01
      • 2016-04-02
      • 2021-08-25
      • 1970-01-01
      • 2017-01-27
      • 2019-04-11
      • 2018-11-30
      相关资源
      最近更新 更多