Permalink
Browse files

Replace selenium-webdriver with wd

selenium-webdriver explicitly blocks any parallel calls to selenium
grid, thus, making parallel testing impossible. Now shooter uses
wd instead which have no such limitations.
keyDown and keyUp actions were removed, because they are not supported
by wd. They didn't work propertly in selenium-webdriver anyway.
  • Loading branch information...
1 parent cf9834d commit b30cf4106492d9c977a0524f9510fe75b3988132 Sergey Tatarintsev committed Mar 6, 2014
Showing with 71 additions and 66 deletions.
  1. +41 −38 lib/browser/actions.js
  2. +25 −24 lib/browser/index.js
  3. +2 −2 lib/element-rect.js
  4. +3 −2 package.json
View
@@ -1,8 +1,6 @@
'use strict';
-var q = require('q'),
- inherit = require('inherit'),
- webdriver = require('selenium-webdriver'),
+var inherit = require('inherit'),
promiseUtil = require('../promise-util');
module.exports = inherit({
@@ -13,72 +11,77 @@ module.exports = inherit({
},
wait: function(millseconds) {
- this._selenimSequence = null;
+ var _this = this;
this._actions.push(function wait() {
- return q.delay(millseconds);
+ return _this._driver.sleep(millseconds);
});
return this;
},
click: function(element, button) {
- this._getSeleniumSequence().click(element, button);
+ var _this = this;
+ this._actions.push(function click() {
+ return _this._driver.clickElement(element, button);
+ });
return this;
},
doubleClick: function(element, button) {
- this._getSeleniumSequence().mouseMove(element, button);
+ var _this = this;
+ this._actions.push(function() {
+ return _this._driver.moveTo(element)
+ .then(function() {
+ return _this._driver.doubleClick(element, button);
+ });
+ });
return this;
},
dragAndDrop: function(element, dragTo) {
- this._getSeleniumSequence().dragAndDrop(element, dragTo);
- return this;
- },
-
- keyDown: function(key) {
- this._getSeleniumSequence().keyDown(key);
- return this;
- },
-
- keyUp: function(key) {
- this._getSeleniumSequence().keyUp(key);
- return this;
+ return this.mouseDown(element)
+ .mouseMove(dragTo)
+ .mouseUp();
},
- mouseDown: function(element, offset) {
- this._getSeleniumSequence().mouseDown(element, offset);
+ mouseDown: function(element, button) {
+ var _this = this;
+ this._actions.push(function mouseDown() {
+ return _this._driver.moveTo(element)
+ .then(function() {
+ return _this._driver.buttonDown(button);
+ });
+ });
return this;
},
- mouseUp: function(element, offset) {
- this._getSeleniumSequence().mouseUp(element, offset);
+ mouseUp: function(element, button) {
+ var _this = this;
+ this._actions.push(function mouseDown() {
+ return _this._driver.moveTo(element)
+ .then(function() {
+ return _this.driver.buttonUp(button);
+ });
+ });
return this;
},
mouseMove: function(element, offset) {
- this._getSeleniumSequence().mouseMove(element, offset);
+ var _this = this;
+ this._actions.push(function mouseMove() {
+ return _this._driver.moveTo(element);
+ });
return this;
},
sendKeys: function(keys) {
- this._getSeleniumSequence().sendKeys(keys);
+ var _this = this;
+ this._actions.push(function sendKeys() {
+ return _this._driver.keys(keys);
+ });
return this;
},
perform: function() {
return promiseUtil.sequence(this._actions);
- },
-
- _getSeleniumSequence: function() {
- if (!this._selenimSequence) {
- var seleniumSequence = new webdriver.ActionSequence(this._driver);
-
- this._actions.push(function runSeleniumSequence() {
- return seleniumSequence.perform();
- });
-
- this._selenimSequence = seleniumSequence;
- }
- return this._selenimSequence;
}
});
View
@@ -1,43 +1,44 @@
'use strict';
var inherit = require('inherit'),
- webdriver = require('selenium-webdriver'),
+ wd = require('wd'),
+ q = require('q'),
elementRect = require('../element-rect'),
Image = require('../image'),
- Actions = require('./actions'),
- By = webdriver.By;
+ Actions = require('./actions');
module.exports = inherit({
__constructor: function(config, name) {
this.name = name;
this.config = config;
- var builder = new webdriver.Builder();
-
- if (config.gridUrl) {
- builder.usingServer(config.gridUrl);
- }
-
- var capabilities = webdriver.Capabilities[name];
-
- this._driver = builder
- .withCapabilities(capabilities())
- .build();
+ this._browser = wd.promiseRemote(config.gridUrl);
},
open: function(url) {
- return this._driver.get(url);
+ var _this = this;
+ return this._browser.init({browserName: this.name}).then(function() {
+ return _this._browser.get(url);
+ });
},
findElements: function(elements) {
- var result = {};
- Object.keys(elements).forEach(function(key) {
- result[key] = this._driver.findElement(By.css(elements[key]));
- }, this);
- return result;
+ var _this = this;
+ return q.all(Object.keys(elements).map(function(key) {
+ return _this.findElement(key)
+ .then(function(element) {
+ return {name: key, element: element};
+ });
+ }))
+ .then(function(elems) {
+ return elems.reduce(function(obj, elem) {
+ obj[elem.name] = elem.element;
+ return obj;
+ }, {});
+ });
},
findElement: function(selector) {
- return this._driver.findElement(By.css(selector));
+ return this._browser.elementByCssSelector(selector);
},
captureState: function (state) {
@@ -62,18 +63,18 @@ module.exports = inherit({
},
takeScreenshot: function() {
- return this._driver.takeScreenshot()
+ return this._browser.takeScreenshot()
.then(function (base64) {
return new Image(new Buffer(base64, 'base64'));
});
},
quit: function() {
- return this._driver.quit();
+ return this._browser.quit();
},
createActionSequence: function() {
- return new Actions(this._driver);
+ return new Actions(this._browser);
}
});
View
@@ -7,7 +7,7 @@ exports.getMultiple = function getMultiple(elements) {
return elements[key];
});
return q.all(elementsArray.map(function(element) {
- return element.getCssValue('display');
+ return element.getComputedCss('display');
}))
.then(function(displays) {
var visibleElements = elementsArray.filter(function(element, index) {
@@ -30,7 +30,7 @@ exports.get = function get(element) {
});
})
.then(function(rect) {
- return element.getCssValue('box-shadow').then(function(boxShadow) {
+ return element.getComputedCss('box-shadow').then(function(boxShadow) {
var shadows = parseBoxShadow(boxShadow);
return adjustRect(rect, shadows);
});
View
@@ -7,15 +7,16 @@
},
"dependencies": {
"gm": "~1.14.2",
- "selenium-webdriver": "~2.39.0",
+ "selenium-webdriver": "~2.40.0",
"inherit": "~2.1.0",
"coa": "~0.4.0",
"js-yaml": "~3.0.1",
"q": "~1.0.0",
"q-io": "~1.10.8",
"chalk": "~0.4.0",
"temp": "~0.6.0",
- "handlebars": "~1.3.0"
+ "handlebars": "~1.3.0",
+ "wd": "~0.2.11"
},
"devDependencies": {
"mocha": "~1.17.1",

0 comments on commit b30cf41

Please sign in to comment.