2017-07-03 83 views
1

我使用postman和newman來執行自動化測試,我做了一個JUnit導出爲了在TFS中利用它們。 然而,當我打開我的.xml報告,故障表示如下:郵遞員/紐曼junit報告定製

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

我想知道是否可以自定義「失敗1次。」爲了信息傳遞更相關數據有關失敗(即JSON身體錯誤和說明)

謝謝

亞歷山大

回答

0

好了,終於讓我找到了如何進行(不乾淨的方式,但足以滿足我的目的,迄今爲止):

我影響文件C:\Users\<myself>\AppData\Roaming\npm\node_modules\newman\lib\reporters\junit\index.js

請求的數據和響應可以從「執行」的對象被回收:

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'object:

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沒有「堆」參數(它被命名爲「堆棧跟蹤」)顯示堆棧。

最後故障數據(在測試步驟/測試用例電平)可以從 '故障' 對象被回收:

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

從該I提取:

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

對於我的目的,我添加從jsonExecutions到我的測試套件錯誤數據的響應詳細信息,這在XML報告中比以前更詳細。

如果執行此清潔/更聰明的辦法,不要猶豫,告訴我,我會感激

下一步:做清潔創建自定義的記者。 :)

亞歷山大