Currently, I am utilizing Selenium to navigate an AngularJS website and am keen on generating a comprehensive catalog of all errors that are thrown (my main focus is on lex errors). AngularJS provides access to $exceptionHandler for altering exception handling practices. However, I prefer not to make extensive modifications to the application code since these tests are conducted remotely.
In my case, with Firefox usage, attempting browser.manage().logs() results in failure. It seems like this issue is closely linked to Log console errors using protractor - refer to this Stack Overflow response.
I have experimentally employed window.onerror
and
window.addEventListener('error', () => { ... });
, but unfortunately, neither of them captures the thrown error. I am beginning to suspect if there is some mechanism within AngularJS that obstructs propagation to the window.
This is what I aim to achieve:
window.thrownErrors = [];
[Some global object].throw = (error) => {
console.error(error);
window.thrownErrors.push(error);
}
throw new Error('throw test');
console.log(window.thrownErrors); // => ['throw test']