有没有办法查看selenium webdriverjs测试可能生成的浏览器日志消息(例如console.log)?
答案 0 :(得分:5)
我理解它的方式你想看到被测系统产生的消息?试试这个:
var logBrowserMessages = function(logEntries, driver, logging, cb) {
return driver.manage().logs().get(logging.Type.BROWSER).then(function(entries) {
entries.forEach(function(entry) {
logEntries = logEntries + entry.level.name + ': ' + entry.message + '\n';
});
logEntries = logEntries + "\n";
console.log('final entries:' + logEntries);
return cb();
});
};
您还需要:
var logging = require('selenium-webdriver').logging;
设置带有记录优先级的驱动程序:
var prefs = new logging.Preferences();
prefs.setLevel(logging.Type.BROWSER, logging.Level.ALL);
driver = new webdriver.Builder()
.withCapabilities(webdriver.Capabilities.chrome())
.setLoggingPrefs(prefs)
.build();
然后你可以使用logBrowserMessages:
var doStuff = function(driver, logging) {
return logBrowserMessages('', driver, logging, function() {
//Do stuff
});
});
};