Postman/Newman junit 报表自定义

Postman/Newman junit report customization

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

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

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

谢谢

亚历山大

好吧,我终于找到了如何继续(不是一个干净的方法,但到目前为止足以满足我的目的):

我影响文件C:\Users\<myself>\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' 对象中恢复错误数据(在测试 case/testsuite 级别):

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')。

最终可以从 'failures' 对象恢复故障数据(在测试 step/testcase 级别):

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

我从中提取:

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

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

如果有 cleaner/smarter 方法来执行此操作,请告诉我,我将不胜感激

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

亚历山大