[英]Json File Creation in nodeJS
如果我的理解是正確的,那么您正在使用Protractor自動化AngularJS測試,並將結果寫為JSON,以便報告/一旦完成就解析回去? 如果是這樣,您可以簡單地將結果存儲為Java中的對象,然后使用fs節點包將其寫出。
編寫JSON報告文件
var fs = require('fs');
//..Protractor .. and other logic..
var results = { Project : "xxx" , ....};
//...more of that assignment....
//You could use JSON.parse() or JSON.stringify() to read/convert this object to string vice versa and fs package to read/write it to file.
fs.writeFile("/tmp/testreport.json", JSON.stringify(results), function(err) {
if(err) {
return console.log(err);
}
console.log("The test report file was saved as JSON file!");
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.