Skip to content

Commit

Permalink
feat: add support for buttondown/up & moveto
Browse files Browse the repository at this point in the history
These three ops let us simulate drag-and-drop.  The modern equivalent
would be "actions", but AFAICT this isn't fully implemented in webdrivers
yet.

* add toplevel `buttonDown()` and `buttonUp()` functions
* add `Element#movePointerRelativeTo()` method
* DRY the docs a bit
* fix duplicate `assertive` include
  • Loading branch information
dbushong committed Apr 18, 2016
1 parent 8df40e5 commit 35ea4ca
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 104 deletions.
191 changes: 99 additions & 92 deletions README.md

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions lib/element.js
Expand Up @@ -152,6 +152,20 @@ module.exports = Element = (function() {
this.http.post(this.root + "/clear");
};

Element.prototype.movePointerRelativeTo = function(xOffset, yOffset) {
var opts;
opts = {
element: this.elementId
};
if (xOffset != null) {
opts.xoffset = xOffset;
}
if (yOffset != null) {
opts.yoffset = yOffset;
}
this.http.post('/moveto', opts);
};

return Element;

})();
Expand Down
15 changes: 9 additions & 6 deletions lib/index.js
Expand Up @@ -30,7 +30,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
var WebDriver, assert, buildRequester, createAlertApi, createCookieApi, createDebugApi, createElementApi, createLocalStorageApi, createLocationApi, createNavigationApi, createPageApi, createSession, createWindowApi, extend, http, parseResponseData,
var WebDriver, assert, buildRequester, createAlertApi, createCookieApi, createDebugApi, createElementApi, createLocalStorageApi, createLocationApi, createNavigationApi, createPageApi, createPointerApi, createSession, createWindowApi, extend, http, parseResponseData,
slice = [].slice;

assert = require('assertive');
Expand All @@ -49,17 +49,19 @@ createAlertApi = require('./alert_api');

createCookieApi = require('./cookie_api');

createElementApi = require('./element_api');
createDebugApi = require('./debug_api');

createLocationApi = require('./location_api');
createElementApi = require('./element_api');

createLocalStorageApi = require('./local_storage_api');

createLocationApi = require('./location_api');

createNavigationApi = require('./navigation_api');

createPageApi = require('./page_api');

createDebugApi = require('./debug_api');
createPointerApi = require('./pointer_api');

createWindowApi = require('./window_api');

Expand All @@ -76,12 +78,13 @@ module.exports = WebDriver = (function() {
this.http = http(request, serverUrl, sessionId);
extend(this, createAlertApi(this.http));
extend(this, createCookieApi(this.http));
extend(this, createDebugApi(this.http));
extend(this, createElementApi(this.http));
extend(this, createLocationApi(this.http));
extend(this, createLocalStorageApi(this.http));
extend(this, createLocationApi(this.http));
extend(this, createNavigationApi(this.http));
extend(this, createPageApi(this.http));
extend(this, createDebugApi(this.http));
extend(this, createPointerApi(this.http));
extend(this, createWindowApi(this.http));
}

Expand Down
52 changes: 52 additions & 0 deletions lib/pointer_api.js
@@ -0,0 +1,52 @@

/*
Copyright (c) 2013, Groupon, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
Neither the name of GROUPON nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
module.exports = function(http) {
return {
buttonDown: function(button) {
if (button == null) {
button = 0;
}
http.post('/buttondown', {
button: button
});
},
buttonUp: function(button) {
if (button == null) {
button = 0;
}
http.post('/buttonup', {
button: button
});
}
};
};
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -27,7 +27,7 @@
}
},
"dependencies": {
"assertive": "^1.4.0",
"assertive": "^2.0.0",
"bindings": "~1.2.1",
"caseless": "~0.11.0",
"coffee-script": "^1.10.0",
Expand All @@ -37,7 +37,6 @@
"nan": "^2.0.9"
},
"devDependencies": {
"assertive": "^2.0.0",
"mocha": "^2.0.0",
"nlm": "^2.0.0",
"nodemon": "^1.0.0"
Expand Down
7 changes: 7 additions & 0 deletions src/element.coffee
Expand Up @@ -123,6 +123,13 @@ module.exports = class Element
@http.post "#{@root}/clear"
return

movePointerRelativeTo: (xOffset, yOffset) ->
opts = element: @elementId
opts.xoffset = xOffset if xOffset?
opts.yoffset = yOffset if yOffset?
@http.post '/moveto', opts
return

elementOrNull = Element.elementOrNull = (create) ->
try
create()
Expand Down
10 changes: 6 additions & 4 deletions src/index.coffee
Expand Up @@ -39,12 +39,13 @@ buildRequester = require './request'

createAlertApi = require './alert_api'
createCookieApi = require './cookie_api'
createDebugApi = require './debug_api'
createElementApi = require './element_api'
createLocationApi = require './location_api'
createLocalStorageApi = require './local_storage_api'
createLocationApi = require './location_api'
createNavigationApi = require './navigation_api'
createPageApi = require './page_api'
createDebugApi = require './debug_api'
createPointerApi = require './pointer_api'
createWindowApi = require './window_api'

module.exports = class WebDriver
Expand All @@ -59,12 +60,13 @@ module.exports = class WebDriver

extend this, createAlertApi(@http)
extend this, createCookieApi(@http)
extend this, createDebugApi(@http)
extend this, createElementApi(@http)
extend this, createLocationApi(@http)
extend this, createLocalStorageApi(@http)
extend this, createLocationApi(@http)
extend this, createNavigationApi(@http)
extend this, createPageApi(@http)
extend this, createDebugApi(@http)
extend this, createPointerApi(@http)
extend this, createWindowApi(@http)

on: (event, callback) ->
Expand Down
39 changes: 39 additions & 0 deletions src/pointer_api.coffee
@@ -0,0 +1,39 @@
###
Copyright (c) 2013, Groupon, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
Neither the name of GROUPON nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
###
module.exports = (http) ->
buttonDown: (button=0) ->
http.post '/buttondown', { button }
return

buttonUp: (button=0) ->
http.post '/buttonup', { button }
return

0 comments on commit 35ea4ca

Please sign in to comment.