节点/量angular器等待承诺解决之前继续

我正在写一个能够获得selenium的类,并将这个值存储在类中。 它公开了一个使用类中获得的会话来获取selenium节点的方法。 但是,当JavaScript类调用我的新类getSeleniumNode返回未定义。 我敢肯定,这是因为getSeleniumNode不等待Web请求完成处理,但我不知道如何重新devise它的工作

var base = require(__paths.e2e.pages + '/base'), urlParse = require('url-parse'), request = require('sync-request'); module.exports = function (options) { var self = base(options); browser.getProcessedConfig().then(function (config) { self.seleniumHub = new urlParse(config.seleniumAddress); console.log(self.seleniumHub.host); browser.driver.getCapabilities().then(function (capabilities) { self.capabilities = capabilities; }); }); self.getSessionId = function () { return self.capabilities.caps_[ 'webdriver.remote.sessionid']; }; self.getPlatform = function () { return self.capabilities.platform; }; self.getBrowserName = function () { return self.capabilities.browserName; }; self.getBrowserVersion = function () { return self.capabilities.version; }; self.getSeleniumNode = function () { var url = 'http://' + self.seleniumHub.host + "/grid/api/testsession?session=" + capabilities.caps_[ 'webdriver.remote.sessionid']; var response = request('GET', url); var testSession = JSON.parse(response.getBody().toString()); return new urlParse(testSession.proxyId); }; return self; }; 

而我这个叫这个的class是

 var base = require(__paths.e2e.pages + '/base'); var seleniumCapabilities = require(__paths.e2e.lib + '/seleniumCapabilities')(); module.exports = function (options) { var self = base(options); console.log(seleniumCapabilities.getSeleniumNode()); return self; }; 

我运行这个e2etesting时得到的相关控制台输出是

 undefined -- this is the call from console.log(seleniumCapabilities.getSeleniumNode()); localhost:4444 --- this is the call from console.log(seleniumCapabilities.getSeleniumNode()); 

       

网上收集的解决方案 "节点/量angular器等待承诺解决之前继续"