捕獲在瀏覽器中拋出的 JavaScript 異常。

用法

                    .captureBrowserExceptions(onExceptionCallback)
                

範例

 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());
   });
 });

參數

名稱 類型 描述
onExceptionCallback 函式

每當瀏覽器中拋出新異常時調用的回呼函式。