Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Merge wd port
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Tatarintsev committed Mar 6, 2014
2 parents cf9834d + b30cf41 commit a1c92e0
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 66 deletions.
79 changes: 41 additions & 38 deletions lib/browser/actions.js
@@ -1,8 +1,6 @@
'use strict'; 'use strict';


var q = require('q'), var inherit = require('inherit'),
inherit = require('inherit'),
webdriver = require('selenium-webdriver'),
promiseUtil = require('../promise-util'); promiseUtil = require('../promise-util');


module.exports = inherit({ module.exports = inherit({
Expand All @@ -13,72 +11,77 @@ module.exports = inherit({
}, },


wait: function(millseconds) { wait: function(millseconds) {
this._selenimSequence = null; var _this = this;
this._actions.push(function wait() { this._actions.push(function wait() {
return q.delay(millseconds); return _this._driver.sleep(millseconds);
}); });
return this; return this;
}, },


click: function(element, button) { 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; return this;
}, },


doubleClick: function(element, button) { 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; return this;
}, },


dragAndDrop: function(element, dragTo) { dragAndDrop: function(element, dragTo) {
this._getSeleniumSequence().dragAndDrop(element, dragTo); return this.mouseDown(element)
return this; .mouseMove(dragTo)
}, .mouseUp();

keyDown: function(key) {
this._getSeleniumSequence().keyDown(key);
return this;
},

keyUp: function(key) {
this._getSeleniumSequence().keyUp(key);
return this;
}, },


mouseDown: function(element, offset) { mouseDown: function(element, button) {
this._getSeleniumSequence().mouseDown(element, offset); var _this = this;
this._actions.push(function mouseDown() {
return _this._driver.moveTo(element)
.then(function() {
return _this._driver.buttonDown(button);
});
});
return this; return this;
}, },


mouseUp: function(element, offset) { mouseUp: function(element, button) {
this._getSeleniumSequence().mouseUp(element, offset); var _this = this;
this._actions.push(function mouseDown() {
return _this._driver.moveTo(element)
.then(function() {
return _this.driver.buttonUp(button);
});
});
return this; return this;
}, },


mouseMove: function(element, offset) { mouseMove: function(element, offset) {
this._getSeleniumSequence().mouseMove(element, offset); var _this = this;
this._actions.push(function mouseMove() {
return _this._driver.moveTo(element);
});
return this; return this;
}, },


sendKeys: function(keys) { sendKeys: function(keys) {
this._getSeleniumSequence().sendKeys(keys); var _this = this;
this._actions.push(function sendKeys() {
return _this._driver.keys(keys);
});
return this; return this;
}, },


perform: function() { perform: function() {
return promiseUtil.sequence(this._actions); 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;
} }
}); });
49 changes: 25 additions & 24 deletions lib/browser/index.js
@@ -1,43 +1,44 @@
'use strict'; 'use strict';


var inherit = require('inherit'), var inherit = require('inherit'),
webdriver = require('selenium-webdriver'), wd = require('wd'),
q = require('q'),
elementRect = require('../element-rect'), elementRect = require('../element-rect'),
Image = require('../image'), Image = require('../image'),
Actions = require('./actions'), Actions = require('./actions');
By = webdriver.By;


module.exports = inherit({ module.exports = inherit({
__constructor: function(config, name) { __constructor: function(config, name) {
this.name = name; this.name = name;
this.config = config; this.config = config;
var builder = new webdriver.Builder(); this._browser = wd.promiseRemote(config.gridUrl);

if (config.gridUrl) {
builder.usingServer(config.gridUrl);
}

var capabilities = webdriver.Capabilities[name];

this._driver = builder
.withCapabilities(capabilities())
.build();
}, },


open: function(url) { 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) { findElements: function(elements) {
var result = {}; var _this = this;
Object.keys(elements).forEach(function(key) { return q.all(Object.keys(elements).map(function(key) {
result[key] = this._driver.findElement(By.css(elements[key])); return _this.findElement(key)
}, this); .then(function(element) {
return result; return {name: key, element: element};
});
}))
.then(function(elems) {
return elems.reduce(function(obj, elem) {
obj[elem.name] = elem.element;
return obj;
}, {});
});
}, },


findElement: function(selector) { findElement: function(selector) {
return this._driver.findElement(By.css(selector)); return this._browser.elementByCssSelector(selector);
}, },


captureState: function (state) { captureState: function (state) {
Expand All @@ -62,18 +63,18 @@ module.exports = inherit({
}, },


takeScreenshot: function() { takeScreenshot: function() {
return this._driver.takeScreenshot() return this._browser.takeScreenshot()
.then(function (base64) { .then(function (base64) {
return new Image(new Buffer(base64, 'base64')); return new Image(new Buffer(base64, 'base64'));
}); });
}, },


quit: function() { quit: function() {
return this._driver.quit(); return this._browser.quit();
}, },


createActionSequence: function() { createActionSequence: function() {
return new Actions(this._driver); return new Actions(this._browser);
} }


}); });
4 changes: 2 additions & 2 deletions lib/element-rect.js
Expand Up @@ -7,7 +7,7 @@ exports.getMultiple = function getMultiple(elements) {
return elements[key]; return elements[key];
}); });
return q.all(elementsArray.map(function(element) { return q.all(elementsArray.map(function(element) {
return element.getCssValue('display'); return element.getComputedCss('display');
})) }))
.then(function(displays) { .then(function(displays) {
var visibleElements = elementsArray.filter(function(element, index) { var visibleElements = elementsArray.filter(function(element, index) {
Expand All @@ -30,7 +30,7 @@ exports.get = function get(element) {
}); });
}) })
.then(function(rect) { .then(function(rect) {
return element.getCssValue('box-shadow').then(function(boxShadow) { return element.getComputedCss('box-shadow').then(function(boxShadow) {
var shadows = parseBoxShadow(boxShadow); var shadows = parseBoxShadow(boxShadow);
return adjustRect(rect, shadows); return adjustRect(rect, shadows);
}); });
Expand Down
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -7,15 +7,16 @@
}, },
"dependencies": { "dependencies": {
"gm": "~1.14.2", "gm": "~1.14.2",
"selenium-webdriver": "~2.39.0", "selenium-webdriver": "~2.40.0",
"inherit": "~2.1.0", "inherit": "~2.1.0",
"coa": "~0.4.0", "coa": "~0.4.0",
"js-yaml": "~3.0.1", "js-yaml": "~3.0.1",
"q": "~1.0.0", "q": "~1.0.0",
"q-io": "~1.10.8", "q-io": "~1.10.8",
"chalk": "~0.4.0", "chalk": "~0.4.0",
"temp": "~0.6.0", "temp": "~0.6.0",
"handlebars": "~1.3.0" "handlebars": "~1.3.0",
"wd": "~0.2.11"
}, },
"devDependencies": { "devDependencies": {
"mocha": "~1.17.1", "mocha": "~1.17.1",
Expand Down

0 comments on commit a1c92e0

Please sign in to comment.