我想在测试期间检查特定的控制台日志
it('should return logs', function(done) {
browser
.log('browser').then(function(logs){
console.log(logs);
})
...
});
我得到的是:
[ { level: 'INFO',
message: 'https://localhost:3000/ 42:14 "foo"',
timestamp: 1485785320222 },
{ level: 'INFO',
message: 'https://localhost:3000/ 43:14 "bar"',
timestamp: 1485785320222 },
{ level: 'INFO',
message: 'https://localhost:3000/ 46:14 Array[6]',
timestamp: 1485785320225 },
{ level: 'SEVERE',
message: 'https://localhost:3000/favicon.ico - Failed to load resource: the server responded with a status of 404 (Not Found)',
timestamp: 1485785320298 } ]
所以它应该只返回一个日志条目列表,例如“foo”和“bar”,这样我就可以检查它是否等于我的假设值。
我现在不确定是否需要“for..in”来构建我可以重用的方法,或者只是循环遍历多个对象并查找logs.value.message并用“” trim 部分。
最佳答案
仅过滤与您要查找的内容匹配的日志可能是最简单/最容易理解的:
it('should return logs', function(done) {
browser
.log('browser').then(function(logs){
console.log(logs.filter(function (logItem) {
return logItem.message.match(/"foo"|"bar"$/);
});
})
...
});
关于javascript - 返回数组中的特定对象值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41939014/