From 29627f42bb7404f66e3a76ba3cbd85256b408fb6 Mon Sep 17 00:00:00 2001 From: Craig Nishina Date: Mon, 29 Feb 2016 18:34:59 -0800 Subject: [PATCH] chore(selenium) - upgrade to selenium webdriver v 2.52.0 --- lib/debugger/debuggerCommons.js | 4 ++-- lib/driverProviders/attachSession.js | 9 ++++----- lib/driverProviders/driverProvider.js | 21 +++++++++++++-------- lib/driverProviders/mock.js | 13 +++++-------- lib/element.js | 5 ++--- lib/protractor.js | 18 ++++++++++-------- package.json | 2 +- 7 files changed, 37 insertions(+), 35 deletions(-) diff --git a/lib/debugger/debuggerCommons.js b/lib/debugger/debuggerCommons.js index 2f9f948ab..6f6052a2c 100644 --- a/lib/debugger/debuggerCommons.js +++ b/lib/debugger/debuggerCommons.js @@ -17,8 +17,8 @@ exports.attachDebugger = function(pid, opt_port) { client.once('ready', function() { client.setBreakpoint({ type: 'scriptRegExp', - target: '.*executors\.js', //jshint ignore:line - line: 40 + target: '.*command\.js', //jshint ignore:line + line: 249 }, function() { process.send('ready'); client.reqContinue(function() { diff --git a/lib/driverProviders/attachSession.js b/lib/driverProviders/attachSession.js index 99195b6e3..d63461fbf 100644 --- a/lib/driverProviders/attachSession.js +++ b/lib/driverProviders/attachSession.js @@ -8,7 +8,7 @@ var util = require('util'), q = require('q'), DriverProvider = require('./driverProvider'), log = require('../logger'), - webdriver = require('selenium-webdriver'), + WebDriver = require('selenium-webdriver').WebDriver, executors = require('selenium-webdriver/executors'); var AttachedSessionDriverProvider = function(config) { @@ -33,13 +33,12 @@ AttachedSessionDriverProvider.prototype.setupEnv = function() { * Getting a new driver by attaching an existing session. * * @public - * @return {webdriver.WebDriver} webdriver instance + * @return {WebDriver} webdriver instance */ AttachedSessionDriverProvider.prototype.getNewDriver = function() { var executor = executors.createExecutor(this.config_.seleniumAddress); - var newDriver; - newDriver = new webdriver.WebDriver - .attachToSession(executor, this.config_.seleniumSessionId); + var newDriver = WebDriver + .attachToSession(executor, this.config_.seleniumSessionId); this.drivers_.push(newDriver); return newDriver; }; diff --git a/lib/driverProviders/driverProvider.js b/lib/driverProviders/driverProvider.js index ba2e2df10..2715065b7 100644 --- a/lib/driverProviders/driverProvider.js +++ b/lib/driverProviders/driverProvider.js @@ -58,15 +58,20 @@ DriverProvider.prototype.quitDriver = function(driver) { } var deferred = q.defer(); - driver.getSession().then(function(session_) { - if (session_) { - driver.quit().then(function() { + if (driver.getSession() === undefined) { + deferred.resolve(); + } + else { + driver.getSession().then(function(session_) { + if (session_) { + driver.quit().then(function() { + deferred.resolve(); + }); + } else { deferred.resolve(); - }); - } else { - deferred.resolve(); - } - }); + } + }); + } return deferred.promise; }; diff --git a/lib/driverProviders/mock.js b/lib/driverProviders/mock.js index f9b140908..dcf21b351 100644 --- a/lib/driverProviders/mock.js +++ b/lib/driverProviders/mock.js @@ -14,15 +14,12 @@ var MockExecutor = function() { }; /** - * @param {!webdriver.Command} command The command to execute. - * @param {function(Error, !bot.response.ResponseObject=)} callback the function - * to invoke when the command response is ready. + * An execute function that returns a promise with a test value. */ -MockExecutor.prototype.execute = function(command, callback) { - callback(null, { - status: '0', - value: 'test_response' - }); +MockExecutor.prototype.execute = function() { + var deferred = q.defer(); + deferred.resolve({value: 'test_response'}); + return deferred.promise; }; var MockDriverProvider = function(config) { diff --git a/lib/element.js b/lib/element.js index df9852476..f74d8f0f7 100644 --- a/lib/element.js +++ b/lib/element.js @@ -340,7 +340,7 @@ ElementArrayFinder.prototype.count = function() { return this.getWebElements().then(function(arr) { return arr.length; }, function(err) { - if (err.code == webdriver.error.ErrorCode.NO_SUCH_ELEMENT) { + if (err.code == webdriver.error.NoSuchElementError()) { return 0; } else { throw err; @@ -671,8 +671,7 @@ var ElementFinder = function(ptor, elementArrayFinder) { var getWebElements = function() { return elementArrayFinder.getWebElements().then(function(webElements) { if (webElements.length === 0) { - throw new webdriver.error.Error( - webdriver.error.ErrorCode.NO_SUCH_ELEMENT, + throw new webdriver.error.NoSuchElementError( 'No element found using locator: ' + elementArrayFinder.locator_.toString()); } else { diff --git a/lib/protractor.js b/lib/protractor.js index df42f92a6..594a83490 100644 --- a/lib/protractor.js +++ b/lib/protractor.js @@ -1,6 +1,8 @@ var util = require('util'); var url = require('url'); var webdriver = require('selenium-webdriver'); +var Command = require('selenium-webdriver/lib/command').Command; +var CommandName = require('selenium-webdriver/lib/command').Name; var helper = require('./util'); var log = require('./logger'); var ElementArrayFinder = require('./element').ElementArrayFinder; @@ -105,16 +107,16 @@ var Protractor = function(webdriverInstance, opt_baseUrl, opt_rootElement, var methodsToSync = ['getCurrentUrl', 'getPageSource', 'getTitle']; // Mix all other driver functionality into Protractor. - for (var method in webdriverInstance) { - if (!this[method] && typeof webdriverInstance[method] == 'function') { + var self = this; + Object.getOwnPropertyNames(webdriver.WebDriver.prototype).forEach(function(method) { + if (!self[method] && typeof webdriverInstance[method] == 'function') { if (methodsToSync.indexOf(method) !== -1) { - mixin(this, webdriverInstance, method, this.waitForAngular.bind(this)); + mixin(self, webdriverInstance, method, self.waitForAngular.bind(self)); } else { - mixin(this, webdriverInstance, method); + mixin(self, webdriverInstance, method); } } - } - var self = this; + }); /** * The wrapped webdriver instance. Use this to interact with pages that do @@ -304,7 +306,7 @@ Protractor.prototype.executeScript_ = function(script, description) { } return this.driver.schedule( - new webdriver.Command(webdriver.CommandName.EXECUTE_SCRIPT). + new Command(CommandName.EXECUTE_SCRIPT). setParameter('script', script). setParameter('args', Array.prototype.slice.call(arguments, 2)), description); @@ -328,7 +330,7 @@ Protractor.prototype.executeAsyncScript_ = script = 'return (' + script + ').apply(null, arguments);'; } return this.driver.schedule( - new webdriver.Command(webdriver.CommandName.EXECUTE_ASYNC_SCRIPT). + new Command(CommandName.EXECUTE_ASYNC_SCRIPT). setParameter('script', script). setParameter('args', Array.prototype.slice.call(arguments, 2)), description); diff --git a/package.json b/package.json index 575b6a30c..4a0db52a0 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "q": "1.4.1", "request": "~2.67.0", "saucelabs": "~1.0.1", - "selenium-webdriver": "2.48.2", + "selenium-webdriver": "2.52.0", "source-map-support": "~0.4.0" }, "devDependencies": {