运行 selenium webdriverjs 测试时如何查看浏览器日志消息
How can I see the browser log messages when running a selenium webdriverjs test
有没有办法查看 selenium webdriverjs 测试可能生成的浏览器日志消息(例如 console.log)?
据我了解,您想查看被测系统生成的消息吗?试试这个:
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
});
});
};
有没有办法查看 selenium webdriverjs 测试可能生成的浏览器日志消息(例如 console.log)?
据我了解,您想查看被测系统生成的消息吗?试试这个:
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
});
});
};