Listen to the console events (ex. console.log event) and register callback to process the same.

captureBrowserConsoleLogs() is only available when using Chrome or Edge drivers.

Usage

.captureBrowserConsoleLogs(onEventCallback)

Parameters

Name Type description
onEventCallback function

Callback function called whenever a new console event is captured.

Example

 describe('capture console events', function() {
   it('captures and logs console.log event', function() {
     browser
       .captureBrowserConsoleLogs((event) => {
         console.log(event.type, event.timestamp, event.args[0].value);
       })
       .navigateTo('https://www.google.com')
       .executeScript(function() {
         console.log('here');
       }, []);
   });
 });

Recommended content