如何在Node中为WebDriverJS注册error handling程序?
按照文档中的说明尝试注册error handling程序时,出现错误:
注册一个事件侦听器,以便在有未处理的错误时得到通知。
webdriver.promise.Application。 的getInstance()。 on('uncaughtException',function(e){console.error('有一个未捕获的exception:'+ e.message);});
TypeError: Cannot call method 'getInstance' of undefined
什么是注册error handling程序的正确方法?
在searchWebDriverJS源代码时,我发现这个:
webdriver.promise.Application = {}; webdriver.promise.Application.getInstance = function() { webdriver.promise.logDeprecation_( 'webdriver.promise.Application#getInstance()', 'webdriver.promise.controlFlow()'); return webdriver.promise.controlFlow(); };
所以显然正确的方法是使用:
webdriver.promise.controlFlow().on('uncaughtException', function(e) { console.error('There was an unhandled exception! ' + e); });
我已经testing了这个,它的工作原理。
(显然,我使用的selenium-webdriver的版本不包括这个弃用警告,而是简单地失败了。)
更新:
webdriver.promise.logDeprecation_ = function(oldSig, newSig) { if (window.console) { window.console.log( 'Using deprecated ' + oldSig + ', use ' + newSig + 'instead. This will stop working in Selenium 2.31'); } };
我正在使用Selenium 2.32。