Reputation: 5258
I want to make sure my angular application does not log any errors in the console when loading the page where the application is located.
For that I use protractor and so far I have the following test:
spec.js:
describe('Protractor Demo App', function () {
it('should show all logs', function () {
browser.get('http://localhost:9050/#/10');
browser.sleep(20000)
browser.manage().logs().get('browser').then(function (browserLogs) {
console.log(browserLogs)
browserLogs.forEach(function (log) {
console.log("-------------------");
console.log(log.message);
if (log.level.value > 900) {
throw log.message;
}
});
});
});
});
conf.js:
exports.config = {
framework: 'jasmine2',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js'],
jasmineNodeOpts: {
// If true, display spec names.
isVerbose: true,
// If true, print colors to the terminal.
showColors: true,
// If true, include stack traces in failures.
includeStackTrace: true,
// Default time to wait in ms before a test fails.
defaultTimeoutInterval: 30000
},
capabilities: {
'browserName': 'chrome',
'loggingPrefs' : {"driver": "ALL", "server": "ALL", "browser": "ALL"}
},
};
when I look at the terminal output I get only the first element of the logs. However if I open the console in chrome and look at the logs myself there are more error and warning logs but they are not part of the terminal output. How is this possible, what did I miss ?
Upvotes: 0
Views: 1701
Reputation: 4061
I was running into the same issue, the console errors reported by protractor were not the same as the errors I saw when opening a page in a browser manually. Here is how I solved my problem, I used the navigate()
method instead of get()
. They should be the same but at least in my case they do produce different results in the browser console.
describe('Protractor Demo App', function () {
it('should show all logs', function () {
browser.get('http://localhost:9050/#/10');
// Clear console log
browser.manage().logs().get('browser');
// Load the page again, now with the navigate() method
browser.navigate().to('http://localhost:9050/#/10');
browser.manage().logs().get('browser').then(function (browserLogs) {
console.log(browserLogs);
browserLogs.forEach(function (log) {
console.log("-------------------");
console.log(log.message);
if (log.level.value > 900) {
throw log.message;
}
});
});
});
});
Upvotes: 3