Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit cba1d66

Browse files
committed
Merge pull request #42 from groupon/dpb-dnd
feat: add support for buttondown/up & moveto
2 parents 8df40e5 + 35ea4ca commit cba1d66

File tree

8 files changed

+227
-104
lines changed

8 files changed

+227
-104
lines changed

README.md

Lines changed: 99 additions & 92 deletions
Large diffs are not rendered by default.

lib/element.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,20 @@ module.exports = Element = (function() {
152152
this.http.post(this.root + "/clear");
153153
};
154154

155+
Element.prototype.movePointerRelativeTo = function(xOffset, yOffset) {
156+
var opts;
157+
opts = {
158+
element: this.elementId
159+
};
160+
if (xOffset != null) {
161+
opts.xoffset = xOffset;
162+
}
163+
if (yOffset != null) {
164+
opts.yoffset = yOffset;
165+
}
166+
this.http.post('/moveto', opts);
167+
};
168+
155169
return Element;
156170

157171
})();

lib/index.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3030
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3131
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3232
*/
33-
var WebDriver, assert, buildRequester, createAlertApi, createCookieApi, createDebugApi, createElementApi, createLocalStorageApi, createLocationApi, createNavigationApi, createPageApi, createSession, createWindowApi, extend, http, parseResponseData,
33+
var WebDriver, assert, buildRequester, createAlertApi, createCookieApi, createDebugApi, createElementApi, createLocalStorageApi, createLocationApi, createNavigationApi, createPageApi, createPointerApi, createSession, createWindowApi, extend, http, parseResponseData,
3434
slice = [].slice;
3535

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

5050
createCookieApi = require('./cookie_api');
5151

52-
createElementApi = require('./element_api');
52+
createDebugApi = require('./debug_api');
5353

54-
createLocationApi = require('./location_api');
54+
createElementApi = require('./element_api');
5555

5656
createLocalStorageApi = require('./local_storage_api');
5757

58+
createLocationApi = require('./location_api');
59+
5860
createNavigationApi = require('./navigation_api');
5961

6062
createPageApi = require('./page_api');
6163

62-
createDebugApi = require('./debug_api');
64+
createPointerApi = require('./pointer_api');
6365

6466
createWindowApi = require('./window_api');
6567

@@ -76,12 +78,13 @@ module.exports = WebDriver = (function() {
7678
this.http = http(request, serverUrl, sessionId);
7779
extend(this, createAlertApi(this.http));
7880
extend(this, createCookieApi(this.http));
81+
extend(this, createDebugApi(this.http));
7982
extend(this, createElementApi(this.http));
80-
extend(this, createLocationApi(this.http));
8183
extend(this, createLocalStorageApi(this.http));
84+
extend(this, createLocationApi(this.http));
8285
extend(this, createNavigationApi(this.http));
8386
extend(this, createPageApi(this.http));
84-
extend(this, createDebugApi(this.http));
87+
extend(this, createPointerApi(this.http));
8588
extend(this, createWindowApi(this.http));
8689
}
8790

lib/pointer_api.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
/*
3+
Copyright (c) 2013, Groupon, Inc.
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions
8+
are met:
9+
10+
Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
13+
Redistributions in binary form must reproduce the above copyright
14+
notice, this list of conditions and the following disclaimer in the
15+
documentation and/or other materials provided with the distribution.
16+
17+
Neither the name of GROUPON nor the names of its contributors may be
18+
used to endorse or promote products derived from this software without
19+
specific prior written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22+
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23+
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
*/
33+
module.exports = function(http) {
34+
return {
35+
buttonDown: function(button) {
36+
if (button == null) {
37+
button = 0;
38+
}
39+
http.post('/buttondown', {
40+
button: button
41+
});
42+
},
43+
buttonUp: function(button) {
44+
if (button == null) {
45+
button = 0;
46+
}
47+
http.post('/buttonup', {
48+
button: button
49+
});
50+
}
51+
};
52+
};

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
}
2828
},
2929
"dependencies": {
30-
"assertive": "^1.4.0",
30+
"assertive": "^2.0.0",
3131
"bindings": "~1.2.1",
3232
"caseless": "~0.11.0",
3333
"coffee-script": "^1.10.0",
@@ -37,7 +37,6 @@
3737
"nan": "^2.0.9"
3838
},
3939
"devDependencies": {
40-
"assertive": "^2.0.0",
4140
"mocha": "^2.0.0",
4241
"nlm": "^2.0.0",
4342
"nodemon": "^1.0.0"

src/element.coffee

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ module.exports = class Element
123123
@http.post "#{@root}/clear"
124124
return
125125

126+
movePointerRelativeTo: (xOffset, yOffset) ->
127+
opts = element: @elementId
128+
opts.xoffset = xOffset if xOffset?
129+
opts.yoffset = yOffset if yOffset?
130+
@http.post '/moveto', opts
131+
return
132+
126133
elementOrNull = Element.elementOrNull = (create) ->
127134
try
128135
create()

src/index.coffee

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ buildRequester = require './request'
3939

4040
createAlertApi = require './alert_api'
4141
createCookieApi = require './cookie_api'
42+
createDebugApi = require './debug_api'
4243
createElementApi = require './element_api'
43-
createLocationApi = require './location_api'
4444
createLocalStorageApi = require './local_storage_api'
45+
createLocationApi = require './location_api'
4546
createNavigationApi = require './navigation_api'
4647
createPageApi = require './page_api'
47-
createDebugApi = require './debug_api'
48+
createPointerApi = require './pointer_api'
4849
createWindowApi = require './window_api'
4950

5051
module.exports = class WebDriver
@@ -59,12 +60,13 @@ module.exports = class WebDriver
5960

6061
extend this, createAlertApi(@http)
6162
extend this, createCookieApi(@http)
63+
extend this, createDebugApi(@http)
6264
extend this, createElementApi(@http)
63-
extend this, createLocationApi(@http)
6465
extend this, createLocalStorageApi(@http)
66+
extend this, createLocationApi(@http)
6567
extend this, createNavigationApi(@http)
6668
extend this, createPageApi(@http)
67-
extend this, createDebugApi(@http)
69+
extend this, createPointerApi(@http)
6870
extend this, createWindowApi(@http)
6971

7072
on: (event, callback) ->

src/pointer_api.coffee

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
###
2+
Copyright (c) 2013, Groupon, Inc.
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions
7+
are met:
8+
9+
Redistributions of source code must retain the above copyright notice,
10+
this list of conditions and the following disclaimer.
11+
12+
Redistributions in binary form must reproduce the above copyright
13+
notice, this list of conditions and the following disclaimer in the
14+
documentation and/or other materials provided with the distribution.
15+
16+
Neither the name of GROUPON nor the names of its contributors may be
17+
used to endorse or promote products derived from this software without
18+
specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21+
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
26+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
###
32+
module.exports = (http) ->
33+
buttonDown: (button=0) ->
34+
http.post '/buttondown', { button }
35+
return
36+
37+
buttonUp: (button=0) ->
38+
http.post '/buttonup', { button }
39+
return

0 commit comments

Comments
 (0)