好吧,我终于知道了如何进行(到目前为止,这不是一个干净的方法,但足以满足我的目的):
我影响了文件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”对象中恢复:
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 报告中比以前详细得多。
如果有更清洁/更智能的方法来执行此操作,请随时告诉我,我将不胜感激
下一步:通过创建自定义报告器进行清理。 :)
亚历山大