如何从Meteor上的Selenium错误中恢复?

时间:2016-07-12 19:57:27

标签: node.js selenium meteor selenium-webdriver selenium-chromedriver

我的代码,从一个方法调用Meteor服务器(对于那些不了解Meteor,它运行在Node.js之上的人):

var webdriver = require('selenium-webdriver')

function getPage(page) {

    driver = driver || new webdriver.Builder().forBrowser('chrome').build();

    driver.get(page).catch(function(error){
        throw new Meteor.Error("Can't get page " + page)
    })
}

熟悉Meteor的人知道它通常应该将Meteor.Error传播给客户端。相反,Selenium捕获我的错误并退出代码1,导致服务器重启:

W20160712-12:49:40.093(-7)? (STDERR) 
W20160712-12:49:40.104(-7)? (STDERR) /Users/irinaapex/irina/meteor/selenium/node_modules/selenium-webdriver/lib/promise.js:654
W20160712-12:49:40.104(-7)? (STDERR)     throw error;
W20160712-12:49:40.105(-7)? (STDERR)     ^
W20160712-12:49:40.105(-7)? (STDERR) Error: [Can't get page i]
W20160712-12:49:40.118(-7)? (STDERR)     at imports/somethingSel.js:35:15
W20160712-12:49:40.120(-7)? (STDERR)     at ManagedPromise.invokeCallback_ (/Users/irinaapex/irina/meteor/selenium/node_modules/selenium-webdriver/lib/promise.js:1379:14)
W20160712-12:49:40.121(-7)? (STDERR)     at TaskQueue.execute_ (/Users/irinaapex/irina/meteor/selenium/node_modules/selenium-webdriver/lib/promise.js:2913:14)
W20160712-12:49:40.123(-7)? (STDERR)     at TaskQueue.executeNext_ (/Users/irinaapex/irina/meteor/selenium/node_modules/selenium-webdriver/lib/promise.js:2896:21)
W20160712-12:49:40.124(-7)? (STDERR)     at /Users/irinaapex/irina/meteor/selenium/node_modules/selenium-webdriver/lib/promise.js:2775:27
W20160712-12:49:40.132(-7)? (STDERR)     at /Users/irinaapex/irina/meteor/selenium/node_modules/selenium-webdriver/lib/promise.js:639:7
W20160712-12:49:40.134(-7)? (STDERR)     at /Users/irinaapex/.meteor/packages/promise/.0.8.3-beta.9.1fbal0n++os+web.browser+web.cordova/npm/node_modules/meteor-promise/fiber_pool.js:32:39
=> Exited with code: 1
W20160712-12:49:53.217(-7)? (STDERR) Debugger listening on port 49906
=> Meteor server restarted

似乎我成功将错误消息传递给客户端,我需要阻止Selenium拦截错误。我该怎么做?

1 个答案:

答案 0 :(得分:0)

我相信在这里发生了两件事:

1)调用驱动程序以获取页面是异步的,因此您应该将其包装到Meteor.wrapAsync()调用中。

2)如果你这样做,我认为错误将被同步发送到呼叫的返回值。或者你可以抓住它并将错误抛出为Meteor.error()