.captureBrowserExceptions() Suggest edits
Since: 2.2.0Catch the JavaScript exceptions thrown in the browser.
Usage
.captureBrowserExceptions(onExceptionCallback)
Example
describe('catch browser exceptions', function() {
it('captures the js exceptions thrown in the browser', async function() {
await browser.captureBrowserExceptions((event) => {
console.log('>>> Exception:', event);
});
await browser.navigateTo('https://duckduckgo.com/');
const searchBoxElement = await browser.findElement('input[name=q]');
await browser.executeScript(function(_searchBoxElement) {
_searchBoxElement.setAttribute('onclick', 'throw new Error("Hello world!")');
}, [searchBoxElement]);
await browser.elementIdClick(searchBoxElement.getId());
});
});
Parameters
Name | Type | description |
---|---|---|
onExceptionCallback |
function | Callback function called whenever a new exception is thrown in the browser. |