【发布时间】:2017-01-31 10:21:19
【问题描述】:
状态:
// WebdriverIO log function
browser.log('browser').then(function(logs) {
console.log(logs.value);
});
返回以下数组:
[ { level: 'INFO',
message: 'https://localhost:3000/ 42:14 "foo"',
timestamp: 1485857149752 },
{ level: 'INFO',
message: 'https://localhost:3000/ 43:14 "bar"',
timestamp: 1485857149752 },
{ level: 'INFO',
message: 'https://localhost:3000/ 46:14 Array[6]',
timestamp: 1485857149755 },
{ level: 'SEVERE',
message: 'https://localhost:3000/favicon.ico - Failed to load resource: the server responded with a status of 404 (Not Found)',
timestamp: 1485857149834 } ]
目标:
我想创建一个稍后可以使用的方法,它会返回一个日志条目列表。在我的示例应用程序中就是这种情况:
foo
bar
我不知道如何仅循环获取“消息”键及其值。
要过滤以便只获得“foo”或“bar”,我会使用 RegEx 或 .split 函数。
【问题讨论】:
-
您想过滤以获取仅包含
messages 的列表吗? -
Failed to load resource: the server responded with a status of 404 (Not Found)- 最后一条消息的值? -
如何知道从
"foo"和"bar"中删除引号并将Array[6]更改为[Array]? -
@kukkuz 是的,我需要它来将其用作进一步测试的辅助函数。所以场景是我用 mocha/webdriverio 测试了一个应用程序,并想检查控制台日志是否已建立对等连接等。
标签: javascript arrays unit-testing object webdriver-io