How to capture browser logs after a page navigation in an automation test?
The test:
Click button trigger writing to browser console + does page navigation.
In chrome, there is the option in the Dev Tools: Preserve log upon navigation
Asked
Active
Viewed 542 times
3

Danielag
- 31
- 4
-
Are you sure that the browser logs are not preserved by default if you are using `browser.manage().logs().get('browser')` solution from this [FAQ section](https://github.com/angular/protractor/blob/5fa86dc477b9502a046bac38179f5134e2dcd449/docs/faq.md#how-can-i-get-hold-of-the-browsers-console)? Thanks. – alecxe Nov 24 '15 at 17:19
-
1They are not. After page navigation the console clears – Danielag Nov 24 '15 at 19:57
-
1Another way is to save logs to file: see http://stackoverflow.com/questions/7627113/save-the-console-log-in-chrome-to-a-file – Michael Radionov Nov 25 '15 at 11:11
1 Answers
0
var logmsg;
function aftereach(){
browser.manage().logs().get('browser').then(function (browserLogs) {
browserLogs.forEach(function (log) {
logmsg = logmsg + log;
});
}
You can use global variable to preserve logs. Or you can also store it in text file, if you wish to know its code ask me.

ATUL SHARMA
- 184
- 2
- 12