Line | Hits | Source |
---|---|---|
1 | /*! | |
2 | * | |
3 | * Copyright (c) 2013 Sebastian Golasch | |
4 | * | |
5 | * Permission is hereby granted, free of charge, to any person obtaining a | |
6 | * copy of this software and associated documentation files (the "Software"), | |
7 | * to deal in the Software without restriction, including without limitation | |
8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
9 | * and/or sell copies of the Software, and to permit persons to whom the | |
10 | * Software is furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included | |
13 | * in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
21 | * DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | ||
25 | 1 | 'use strict'; |
26 | ||
27 | /** | |
28 | * Its a webdriver client | |
29 | * | |
30 | * @part Webdriver | |
31 | * @api | |
32 | */ | |
33 | ||
34 | // ext. libs | |
35 | 1 | var fs = require('fs'); |
36 | ||
37 | // int. libs | |
38 | 1 | var WebDriver = require('./lib/webdriver'); |
39 | 1 | var Driver = require('./lib/driver')(WebDriver); |
40 | ||
41 | // include webdriver commands | |
42 | 1 | var dir = __dirname + '/lib/commands/'; |
43 | 1 | fs.readdirSync(dir).forEach(function (file) { |
44 | 13 | var suffix = '.js'; |
45 | 13 | if (file.substring(file.length - suffix.length, file.length) === suffix) { |
46 | 13 | require(dir + file)(Driver); |
47 | } | |
48 | }); | |
49 | ||
50 | // export the webdriver module | |
51 | 1 | module.exports = WebDriver; |
52 |
Line | Hits | Source |
---|---|---|
1 | /*! | |
2 | * | |
3 | * Copyright (c) 2013 Sebastian Golasch | |
4 | * | |
5 | * Permission is hereby granted, free of charge, to any person obtaining a | |
6 | * copy of this software and associated documentation files (the "Software"), | |
7 | * to deal in the Software without restriction, including without limitation | |
8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
9 | * and/or sell copies of the Software, and to permit persons to whom the | |
10 | * Software is furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included | |
13 | * in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
21 | * DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | ||
25 | /** | |
26 | * Cookie related Webdriver endpoints | |
27 | * | |
28 | * @param {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
29 | * @return {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
30 | */ | |
31 | ||
32 | 1 | module.exports = function (Driver) { |
33 | 1 | 'use strict'; |
34 | ||
35 | /** | |
36 | * Retrieve all cookies visible to the current page. | |
37 | * | |
38 | * @method getCookies | |
39 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/cookie | |
40 | * @param {GET} sessionId ID of the session to route the command to | |
41 | */ | |
42 | ||
43 | 1 | Driver.addCommand({ |
44 | name: 'getCookies', | |
45 | url: '/session/:sessionId/cookie', | |
46 | method: 'GET' | |
47 | }); | |
48 | ||
49 | /** | |
50 | * Retrieve a cookies by its name. | |
51 | * | |
52 | * @method getCookie | |
53 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/cookie/:name | |
54 | * @param {GET} sessionId ID of the session to route the command to | |
55 | * @param {GET} name Name of the cookie | |
56 | */ | |
57 | ||
58 | 1 | Driver.addCommand({ |
59 | name: 'getCookie', | |
60 | url: '/session/:sessionId/cookie', | |
61 | method: 'GET' | |
62 | }); | |
63 | ||
64 | /** | |
65 | * Set a cookie. | |
66 | * If the cookie path is not specified, it should be set to "/". | |
67 | * Likewise, if the domain is omitted, | |
68 | * it should default to the current page's domain. | |
69 | * | |
70 | * @method setCookie | |
71 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/cookie | |
72 | * @param {GET} sessionId ID of the session to route the command to | |
73 | * @param {POST} cookie The cookie object | |
74 | */ | |
75 | ||
76 | 1 | Driver.addCommand({ |
77 | name: 'setCookie', | |
78 | url: '/session/:sessionId/cookie', | |
79 | method: 'POST', | |
80 | params: ['cookie'] | |
81 | }); | |
82 | ||
83 | 1 | return Driver; |
84 | }; | |
85 |
Line | Hits | Source |
---|---|---|
1 | /*! | |
2 | * | |
3 | * Copyright (c) 2013 Sebastian Golasch | |
4 | * | |
5 | * Permission is hereby granted, free of charge, to any person obtaining a | |
6 | * copy of this software and associated documentation files (the "Software"), | |
7 | * to deal in the Software without restriction, including without limitation | |
8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
9 | * and/or sell copies of the Software, and to permit persons to whom the | |
10 | * Software is furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included | |
13 | * in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
21 | * DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | ||
25 | /** | |
26 | * Element related Webdriver endpoints | |
27 | * | |
28 | * @param {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
29 | * @return {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
30 | */ | |
31 | ||
32 | 1 | module.exports = function (Driver) { |
33 | 1 | 'use strict'; |
34 | ||
35 | /** | |
36 | * Search for an element on the page, starting from the document root. | |
37 | * The located element will be returned as a WebElement JSON object. | |
38 | * | |
39 | * @method element | |
40 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element | |
41 | * @param {GET} sessionId ID of the session to route the command to | |
42 | * @param {POST} selector The The search target. | |
43 | */ | |
44 | ||
45 | 1 | Driver.addCommand({ |
46 | name: 'element', | |
47 | url: '/session/:sessionId/element', | |
48 | method: 'POST', | |
49 | params: ['selector'], | |
50 | onRequest: function (params) { | |
51 | 0 | var type = 'css selector'; |
52 | 0 | return {using: type, value: params.selector}; |
53 | }, | |
54 | onResponse: function (request, remote, options, deferred, data) { | |
55 | 0 | this.options.id = JSON.parse(data).value.ELEMENT; |
56 | 0 | deferred.resolve(data); |
57 | }, | |
58 | onError: function (request, remote, options, deferred, data) { | |
59 | 0 | data = JSON.parse(data); |
60 | 0 | deferred.resolve(JSON.stringify({'sessionId': data.sessionId, value: -1})); |
61 | } | |
62 | }); | |
63 | ||
64 | /** | |
65 | * Search for multiple elements on the page, starting from the document root. | |
66 | * The located element will be returned as a WebElement JSON object. | |
67 | * | |
68 | * @method elements | |
69 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/elements | |
70 | * @param {GET} sessionId ID of the session to route the command to | |
71 | * @param {POST} selector The The search target. | |
72 | */ | |
73 | ||
74 | 1 | Driver.addCommand({ |
75 | name: 'elements', | |
76 | url: '/session/:sessionId/elements', | |
77 | method: 'POST', | |
78 | params: ['selector'], | |
79 | onRequest: function (params) { | |
80 | 0 | var type = 'css selector'; |
81 | 0 | return {using: type, value: params.selector}; |
82 | }, | |
83 | onResponse: function (request, remote, options, deferred, data) { | |
84 | 0 | deferred.resolve(data); |
85 | }, | |
86 | onError: function (request, remote, options, deferred, data) { | |
87 | 0 | data = JSON.parse(data); |
88 | 0 | deferred.resolve(JSON.stringify({'sessionId': data.sessionId, value: -1})); |
89 | } | |
90 | }); | |
91 | ||
92 | /** | |
93 | * Get the element on the page that currently has focus. | |
94 | * The element will be returned as a WebElement JSON object. | |
95 | * | |
96 | * @method active | |
97 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/active | |
98 | * @param {GET} sessionId ID of the session to route the command to | |
99 | * @param {GET} id ID of the element to route the command to | |
100 | */ | |
101 | ||
102 | 1 | Driver.addCommand({ |
103 | url: '/session/:sessionId/element/:id/active', | |
104 | method: 'GET' | |
105 | }); | |
106 | ||
107 | /** | |
108 | * Get the element on the page that currently has focus. | |
109 | * The element will be returned as a WebElement JSON object. | |
110 | * | |
111 | * @method elementInfo | |
112 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id | |
113 | * @param {GET} sessionId ID of the session to route the command to | |
114 | * @param {GET} elementId ID of the element to route the command to | |
115 | */ | |
116 | ||
117 | 1 | Driver.addCommand({ |
118 | name: 'elementInfo', | |
119 | url: '/session/:sessionId/element/:id', | |
120 | method: 'GET' | |
121 | }); | |
122 | ||
123 | /** | |
124 | * Search for an element on the page, starting from the identified element. | |
125 | * The located element will be returned as a WebElement JSON object. | |
126 | * The table below lists the locator strategies that each server should support. | |
127 | * Each locator must return the first matching element located in the DOM. | |
128 | * | |
129 | * @method childElement | |
130 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/:id/element | |
131 | * @param {GET} sessionId ID of the session to route the command to | |
132 | * @param {GET} elementId ID of the element to route the command to | |
133 | * @param {POST} using The locator strategy to use. // Not yet supported | |
134 | * @param {POST} value The The search target. | |
135 | */ | |
136 | ||
137 | 1 | Driver.addCommand({ |
138 | name: 'childElement', | |
139 | url: '/session/:sessionId/element/:id/element', | |
140 | method: 'GET' | |
141 | }); | |
142 | ||
143 | /** | |
144 | * Search for an element on the page, starting from the identified element. | |
145 | * The located element will be returned as a WebElement JSON object. | |
146 | * The table below lists the locator strategies that each server should support. | |
147 | * Each locator must return the first matching element located in the DOM. | |
148 | * | |
149 | * @method element | |
150 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/:id/element | |
151 | * @param {GET} sessionId ID of the session to route the command to | |
152 | * @param {GET} elementId ID of the element to route the command to | |
153 | * @param {POST} using The locator strategy to use. // Not yet supported | |
154 | * @param {POST} value The The search target. | |
155 | */ | |
156 | ||
157 | 1 | Driver.addCommand({ |
158 | url: '/session/:sessionId/element/:id/elements', | |
159 | method: 'GET' | |
160 | }); | |
161 | ||
162 | /** | |
163 | * Click on an element. | |
164 | * | |
165 | * @method click | |
166 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/click | |
167 | * @param {GET} sessionId ID of the session to route the command to | |
168 | * @param {GET} id ID of the element to route the command to | |
169 | */ | |
170 | ||
171 | 1 | Driver.addCommand({ |
172 | name: 'click', | |
173 | url: '/session/:sessionId/element/:id/click', | |
174 | method: 'POST' | |
175 | }); | |
176 | ||
177 | /** | |
178 | * Submit a FORM element. | |
179 | * The submit command may also be applied to any element that is a descendant of a FORM element. | |
180 | * | |
181 | * @method submit | |
182 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/submit | |
183 | * @param {GET} sessionId ID of the session to route the command to | |
184 | * @param {GET} id ID of the element to route the command to | |
185 | */ | |
186 | ||
187 | 1 | Driver.addCommand({ |
188 | name: 'submit', | |
189 | url: '/session/:sessionId/element/:id/submit', | |
190 | method: 'POST' | |
191 | }); | |
192 | ||
193 | /** | |
194 | * Returns the visible text for the element. | |
195 | * | |
196 | * @method text | |
197 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/text | |
198 | * @param {GET} sessionId ID of the session to route the command to | |
199 | * @param {GET} id ID of the element to route the command to | |
200 | */ | |
201 | ||
202 | 1 | Driver.addCommand({ |
203 | name: 'text', | |
204 | url: '/session/:sessionId/element/:id/text', | |
205 | method: 'GET' | |
206 | }); | |
207 | ||
208 | /** | |
209 | * Send a sequence of key strokes to an element | |
210 | * | |
211 | * @method val | |
212 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/value | |
213 | * @param {GET} sessionId ID of the session to route the command to | |
214 | * @param {GET} id ID of the element to route the command to | |
215 | * @param {POST} text The keys sequence to be sent | |
216 | */ | |
217 | ||
218 | 1 | Driver.addCommand({ |
219 | name: 'val', | |
220 | url: '/session/:sessionId/element/:id/value', | |
221 | method: 'POST', | |
222 | params: ['text'], | |
223 | onRequest: function (params) { | |
224 | 0 | return {value: params.text.split('')}; |
225 | } | |
226 | }); | |
227 | ||
228 | /** | |
229 | * Query for an element's tag name | |
230 | * | |
231 | * @method name | |
232 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/name | |
233 | * @param {GET} sessionId ID of the session to route the command to | |
234 | * @param {GET} elementId ID of the element to route the command to | |
235 | */ | |
236 | ||
237 | 1 | Driver.addCommand({ |
238 | name: 'name', | |
239 | url: '/session/:sessionId/element/:id/name', | |
240 | method: 'GET' | |
241 | }); | |
242 | ||
243 | /** | |
244 | * Clear a TEXTAREA or text INPUT element's value | |
245 | * | |
246 | * @method clear | |
247 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element/:id/clear | |
248 | * @param {GET} sessionId ID of the session to route the command to | |
249 | * @param {GET} elementId ID of the element to route the command to | |
250 | */ | |
251 | ||
252 | 1 | Driver.addCommand({ |
253 | name: 'clear', | |
254 | url: '/session/:sessionId/element/:id/clear', | |
255 | method: 'POST' | |
256 | }); | |
257 | ||
258 | /** | |
259 | * Determine if an OPTION element, or an INPUT element of type checkbox or radiobutton is currently selected | |
260 | * | |
261 | * @method selected | |
262 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/selected | |
263 | * @param {GET} sessionId ID of the session to route the command to | |
264 | * @param {GET} elementId ID of the element to route the command to | |
265 | */ | |
266 | ||
267 | 1 | Driver.addCommand({ |
268 | name: 'selected', | |
269 | url: '/session/:sessionId/element/:id/selected', | |
270 | method: 'GET' | |
271 | }); | |
272 | ||
273 | /** | |
274 | * Determine if an element is currently enabled | |
275 | * | |
276 | * @method enabled | |
277 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/enabled | |
278 | * @param {GET} sessionId ID of the session to route the command to | |
279 | * @param {GET} elementId ID of the element to route the command to | |
280 | */ | |
281 | ||
282 | 1 | Driver.addCommand({ |
283 | name: 'enabled', | |
284 | url: '/session/:sessionId/element/:id/enabled', | |
285 | method: 'GET' | |
286 | }); | |
287 | ||
288 | /** | |
289 | * Get the value of an element's attribute. | |
290 | * | |
291 | * @method getAttribute | |
292 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/attribute/:name | |
293 | * @param {GET} sessionId ID of the session to route the command to | |
294 | * @param {GET} elementId ID of the element to route the command to | |
295 | * @param {GET} attr Attribute that should be fetched | |
296 | */ | |
297 | ||
298 | 1 | Driver.addCommand({ |
299 | name: 'getAttribute', | |
300 | url: '/session/:sessionId/element/:id/attribute/:name', | |
301 | method: 'GET', | |
302 | params: ['name'], | |
303 | onRequest: function (params) { | |
304 | 0 | this.options.name = params.name; |
305 | 0 | return null; |
306 | } | |
307 | }); | |
308 | ||
309 | /** | |
310 | * Test if two element IDs refer to the same DOM element | |
311 | * | |
312 | * @method equals | |
313 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/equals/:other | |
314 | * @param {GET} sessionId ID of the session to route the command to | |
315 | * @param {GET} elementId ID of the element to route the command to | |
316 | * @param {GET} other ID of the element to compare | |
317 | */ | |
318 | ||
319 | 1 | Driver.addCommand({ |
320 | url: '/session/:sessionId/element/:id/equals/:other', | |
321 | method: 'GET' | |
322 | }); | |
323 | ||
324 | /** | |
325 | * Determine an element's location on the page. | |
326 | * The point (0, 0) refers to the upper-left corner of the page. | |
327 | * The element's coordinates are returned as a JSON object with x and y properties. | |
328 | * | |
329 | * @method displayed | |
330 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/displayed | |
331 | * @param {GET} sessionId ID of the session to route the command to | |
332 | * @param {GET} elementId ID of the element to route the command to | |
333 | */ | |
334 | ||
335 | 1 | Driver.addCommand({ |
336 | name: 'displayed', | |
337 | url: '/session/:sessionId/element/:id/displayed', | |
338 | method: 'GET' | |
339 | }); | |
340 | ||
341 | /** | |
342 | * Determine an element's location on the page. The point (0, 0) refers to the upper-left corner of the page. | |
343 | * The element's coordinates are returned as a JSON object with x and y properties. | |
344 | * | |
345 | * @method location | |
346 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/location | |
347 | * @param {GET} sessionId ID of the session to route the command to | |
348 | * @param {GET} elementId ID of the element to route the command to | |
349 | */ | |
350 | ||
351 | 1 | Driver.addCommand({ |
352 | name: 'location', | |
353 | url: '/session/:sessionId/element/:id/location', | |
354 | method: 'GET' | |
355 | }); | |
356 | ||
357 | /** | |
358 | * Determine an element's location on the screen once it has been scrolled into view. | |
359 | * Note: This is considered an internal command and should only be used to determine an element's location for correctly generating native events. | |
360 | * | |
361 | * @method locationInView | |
362 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/location_in_view | |
363 | * @param {GET} sessionId ID of the session to route the command to | |
364 | * @param {GET} elementId ID of the element to route the command to | |
365 | */ | |
366 | ||
367 | 1 | Driver.addCommand({ |
368 | name: 'locationInView', | |
369 | url: '/session/:sessionId/element/:id/location_in_view', | |
370 | method: 'GET' | |
371 | }); | |
372 | ||
373 | /** | |
374 | * Determine an element's size in pixels. | |
375 | * The size will be returned as a JSON object with width and height properties. | |
376 | * | |
377 | * @method size | |
378 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/size | |
379 | * @param {GET} sessionId ID of the session to route the command to | |
380 | * @param {GET} elementId ID of the element to route the command to | |
381 | */ | |
382 | ||
383 | 1 | Driver.addCommand({ |
384 | name: 'size', | |
385 | url: '/session/:sessionId/element/:id/size', | |
386 | method: 'GET' | |
387 | }); | |
388 | ||
389 | /** | |
390 | * Query the value of an element's computed CSS property. | |
391 | * The CSS property to query should be specified using the CSS property name, | |
392 | * not the JavaScript property name (e.g. background-color instead of backgroundColor). | |
393 | * | |
394 | * @method cssProperty | |
395 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/size | |
396 | * @param {GET} sessionId ID of the session to route the command to | |
397 | * @param {GET} elementId ID of the element to route the command to | |
398 | * @param {GET} propertyName Name of the css property to fetch | |
399 | */ | |
400 | ||
401 | 1 | Driver.addCommand({ |
402 | name: 'cssProperty', | |
403 | url: '/session/:sessionId/element/:id/css/:propertyName', | |
404 | method: 'GET', | |
405 | params: ['propertyName'], | |
406 | onRequest: function (params) { | |
407 | 0 | this.options.propertyName = params.propertyName; |
408 | 0 | return null; |
409 | } | |
410 | }); | |
411 | ||
412 | /** | |
413 | * Get the log for a given log type. | |
414 | * Log buffer is reset after each request. | |
415 | * | |
416 | * @method sendKeys | |
417 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/keys | |
418 | * @param {GET} sessionId ID of the session to route the command to | |
419 | * @param {GET} id ID of the element to route the command to | |
420 | * @param {POST} text The keys sequence to be sent | |
421 | */ | |
422 | ||
423 | 1 | Driver.addCommand({ |
424 | name: 'sendKeys', | |
425 | url: '/session/:sessionId/keys', | |
426 | method: 'POST', | |
427 | params: ['text'], | |
428 | onRequest: function (params) { | |
429 | 0 | return {value: params.text.split('')}; |
430 | } | |
431 | }); | |
432 | ||
433 | }; | |
434 |
Line | Hits | Source |
---|---|---|
1 | /*! | |
2 | * | |
3 | * Copyright (c) 2013 Sebastian Golasch | |
4 | * | |
5 | * Permission is hereby granted, free of charge, to any person obtaining a | |
6 | * copy of this software and associated documentation files (the "Software"), | |
7 | * to deal in the Software without restriction, including without limitation | |
8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
9 | * and/or sell copies of the Software, and to permit persons to whom the | |
10 | * Software is furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included | |
13 | * in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
21 | * DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | ||
25 | // ext. modules | |
26 | 1 | var fs = require('fs'); |
27 | ||
28 | /** | |
29 | * Script execution related Webdriver endpoints | |
30 | * | |
31 | * @param {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
32 | * @return {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
33 | */ | |
34 | ||
35 | 1 | module.exports = function (Driver) { |
36 | 1 | 'use strict'; |
37 | ||
38 | /** | |
39 | * Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. | |
40 | * The executed script is assumed to be synchronous and the result of evaluating the script is returned to the client. | |
41 | * The script argument defines the script to execute in the form of a function body. | |
42 | * The value returned by that function will be returned to the client. | |
43 | * The function will be invoked with the provided args array and the values may be accessed | |
44 | * via the arguments object in the order specified. | |
45 | * | |
46 | * @method execute | |
47 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/execute | |
48 | * @param {GET} sessionId ID of the session to route the command to | |
49 | * @param {POST} script The script to execute. | |
50 | * @param {POST} args The script arguments. | |
51 | */ | |
52 | ||
53 | 1 | Driver.addCommand({ |
54 | name: 'execute', | |
55 | url: '/session/:sessionId/execute', | |
56 | method: 'POST', | |
57 | params: ['script', 'arguments'], | |
58 | onRequest: function (raw) { | |
59 | 0 | var script = raw.script.script.replace(/\\n/g, ' ').replace(/\\t/g, ' '); |
60 | 0 | var userArgs = script.substring(script.indexOf('(') + 1, script.indexOf(')')); |
61 | 0 | var dalekScript = String(fs.readFileSync(fs.realpathSync(__dirname + '/../browser/script.js'))); |
62 | ||
63 | 0 | var userscript = script.substring(script.indexOf('{') + 1, script.lastIndexOf('}')); |
64 | 0 | script = dalekScript.replace('__USERARGUMENTS', userArgs); |
65 | 0 | script = script.replace('__SCRIPT;', userscript); |
66 | ||
67 | 0 | return {script: script, args: raw.script.arguments}; |
68 | } | |
69 | }); | |
70 | ||
71 | /** | |
72 | * Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. | |
73 | * The executed script is assumed to be asynchronous and must signal that is done by invoking the provided callback, | |
74 | * which is always provided as the final argument to the function. The value to this callback will be returned to the client. | |
75 | * Asynchronous script commands may not span page loads. | |
76 | * If an unload event is fired while waiting for a script result, an error should be returned to the client. | |
77 | * | |
78 | * The script argument defines the script to execute in teh form of a function body. | |
79 | * The function will be invoked with the provided args array and the values may be accessed | |
80 | * via the arguments object in the order specified. | |
81 | * The final argument will always be a callback function that must be invoked to signal that the script has finished. | |
82 | * | |
83 | * @method executeAsync | |
84 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/execute_async | |
85 | * @param {GET} sessionId ID of the session to route the command to | |
86 | * @param {POST} script The script to execute. | |
87 | * @param {POST} args The script arguments. | |
88 | */ | |
89 | ||
90 | 1 | Driver.addCommand({ |
91 | name: 'executeAsync', | |
92 | url: '/session/:sessionId/execute_async', | |
93 | method: 'POST', | |
94 | params: ['script', 'arguments'] | |
95 | }); | |
96 | ||
97 | }; | |
98 |
Line | Hits | Source |
---|---|---|
1 | /*! | |
2 | * | |
3 | * Copyright (c) 2013 Sebastian Golasch | |
4 | * | |
5 | * Permission is hereby granted, free of charge, to any person obtaining a | |
6 | * copy of this software and associated documentation files (the "Software"), | |
7 | * to deal in the Software without restriction, including without limitation | |
8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
9 | * and/or sell copies of the Software, and to permit persons to whom the | |
10 | * Software is furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included | |
13 | * in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
21 | * DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | ||
25 | /** | |
26 | * Frame execution related Webdriver endpoints | |
27 | * | |
28 | * @param {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
29 | * @return {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
30 | */ | |
31 | ||
32 | 1 | module.exports = function (Driver) { |
33 | 1 | 'use strict'; |
34 | ||
35 | /** | |
36 | * Change focus to another frame on the page. | |
37 | * If the frame id is null, the server should switch to the page's default content. | |
38 | * | |
39 | * @method frame | |
40 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/frame | |
41 | * @param {GET} sessionId ID of the session to route the command to | |
42 | * @param {POST} id Identifier for the frame to change focus to. | |
43 | */ | |
44 | ||
45 | 1 | Driver.addCommand({ |
46 | name: 'frame', | |
47 | url: '/session/:sessionId/frame', | |
48 | method: 'POST', | |
49 | params: ['id'], | |
50 | onRequest: function (elementRaw) { | |
51 | 0 | var id = null; |
52 | 0 | try { |
53 | 0 | var element = JSON.parse(elementRaw.id); |
54 | 0 | id = (element.value && element.value.ELEMENT) ? element.value : null; |
55 | } catch (e) { | |
56 | 0 | id = null; |
57 | } | |
58 | 0 | return {id: id}; |
59 | } | |
60 | }); | |
61 | ||
62 | }; | |
63 |
Line | Hits | Source |
---|---|---|
1 | /*! | |
2 | * | |
3 | * Copyright (c) 2013 Sebastian Golasch | |
4 | * | |
5 | * Permission is hereby granted, free of charge, to any person obtaining a | |
6 | * copy of this software and associated documentation files (the "Software"), | |
7 | * to deal in the Software without restriction, including without limitation | |
8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
9 | * and/or sell copies of the Software, and to permit persons to whom the | |
10 | * Software is furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included | |
13 | * in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
21 | * DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | ||
25 | /** | |
26 | * IME related Webdriver endpoints | |
27 | * | |
28 | * @param {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
29 | * @return {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
30 | */ | |
31 | ||
32 | 1 | module.exports = function (Driver) { |
33 | 1 | 'use strict'; |
34 | ||
35 | /** | |
36 | * Query the server's current status. | |
37 | * The server should respond with a general "HTTP 200 OK" response if it is alive and accepting commands. | |
38 | * The response body should be a JSON object describing the state of the server. | |
39 | * All server implementations should return two basic objects describing the server's current platform | |
40 | * and when the server was built. All fields are optional; if omitted, the client should assume the value is uknown. | |
41 | * Furthermore, server implementations may include additional fields not listed here. | |
42 | * | |
43 | * @method status | |
44 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/status | |
45 | */ | |
46 | ||
47 | 1 | Driver.addCommand({ |
48 | name: 'status', | |
49 | url: '/status', | |
50 | method: 'GET' | |
51 | }); | |
52 | ||
53 | /** | |
54 | * List all available engines on the machine. | |
55 | * To use an engine, it has to be present in this list. | |
56 | * | |
57 | * @method availableEngines | |
58 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/ime/available_engines | |
59 | * @param {GET} sessionId ID of the session to route the command to | |
60 | */ | |
61 | ||
62 | 1 | Driver.addCommand({ |
63 | name: 'availableEngines', | |
64 | url: '/session/:sessionId/ime/available_engines', | |
65 | method: 'GET' | |
66 | }); | |
67 | ||
68 | /** | |
69 | * Get the name of the active IME engine. | |
70 | * The name string is platform specific. | |
71 | * | |
72 | * @method activeEngine | |
73 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/ime/active_engine | |
74 | * @param {GET} sessionId ID of the session to route the command to | |
75 | */ | |
76 | ||
77 | 1 | Driver.addCommand({ |
78 | name: 'activeEngine', | |
79 | url: '/session/:sessionId/ime/active_engine', | |
80 | method: 'GET' | |
81 | }); | |
82 | ||
83 | /** | |
84 | * Indicates whether IME input is active at the moment | |
85 | * | |
86 | * @method activatedEngine | |
87 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/ime/activated | |
88 | * @param {GET} sessionId ID of the session to route the command to | |
89 | */ | |
90 | ||
91 | 1 | Driver.addCommand({ |
92 | name: 'activatedEngine', | |
93 | url: '/session/:sessionId/ime/activated', | |
94 | method: 'GET' | |
95 | }); | |
96 | ||
97 | /** | |
98 | * De-activates the currently-active IME engine | |
99 | * | |
100 | * @method deactivateEngine | |
101 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/ime/deactivate | |
102 | * @param {GET} sessionId ID of the session to route the command to | |
103 | */ | |
104 | ||
105 | 1 | Driver.addCommand({ |
106 | name: 'deactivateEngine', | |
107 | url: '/session/:sessionId/ime/deactivate', | |
108 | method: 'POST' | |
109 | }); | |
110 | ||
111 | /** | |
112 | * Make an engines that is available (appears on the list returned by getAvailableEngines) active. | |
113 | * After this call, the engine will be added to the list of engines loaded in the IME daemon | |
114 | * and the input sent using sendKeys will be converted by the active engine. | |
115 | * Note that this is a platform-independent method of activating IME | |
116 | * (the platform-specific way being using keyboard shortcuts) | |
117 | * | |
118 | * @method activateEngine | |
119 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/ime/activate | |
120 | * @param {GET} sessionId ID of the session to route the command to | |
121 | * @param {POST} engine Name of the engine to activate | |
122 | */ | |
123 | ||
124 | 1 | Driver.addCommand({ |
125 | name: 'activateEngine', | |
126 | url: '/session/:sessionId/ime/activate', | |
127 | method: 'POST', | |
128 | params: ['engine'] | |
129 | }); | |
130 | ||
131 | }; | |
132 |
Line | Hits | Source |
---|---|---|
1 | /*! | |
2 | * | |
3 | * Copyright (c) 2013 Sebastian Golasch | |
4 | * | |
5 | * Permission is hereby granted, free of charge, to any person obtaining a | |
6 | * copy of this software and associated documentation files (the "Software"), | |
7 | * to deal in the Software without restriction, including without limitation | |
8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
9 | * and/or sell copies of the Software, and to permit persons to whom the | |
10 | * Software is furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included | |
13 | * in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
21 | * DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | ||
25 | /** | |
26 | * Interaction related Webdriver endpoints | |
27 | * | |
28 | * @param {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
29 | * @return {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
30 | */ | |
31 | ||
32 | 1 | module.exports = function (Driver) { |
33 | 1 | 'use strict'; |
34 | ||
35 | /** | |
36 | * Move the mouse by an offset of the specificed element. | |
37 | * If no element is specified, the move is relative to the current mouse cursor. | |
38 | * If an element is provided but no offset, the mouse will be moved to the center of the element. | |
39 | * If the element is not visible, it will be scrolled into view. | |
40 | * | |
41 | * @method moveto | |
42 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/moveto | |
43 | * @param {GET} sessionId ID of the session to route the command to | |
44 | * @param {POST} element Opaque ID assigned to the element to move to, as described in the WebElement JSON Object. If not specified or is null, the offset is relative to current position of the mouse. | |
45 | * @param {POST} xoffset X offset to move to, relative to the top-left corner of the element. If not specified, the mouse will move to the middle of the element. | |
46 | * @param {POST} yoffset Y offset to move to, relative to the top-left corner of the element. If not specified, the mouse will move to the middle of the element. | |
47 | */ | |
48 | ||
49 | 1 | Driver.addCommand({ |
50 | name: 'moveto', | |
51 | url: '/session/:sessionId/moveto', | |
52 | method: 'POST', | |
53 | params: ['element', 'xoffset', 'yoffset'], | |
54 | onRequest: function (params) { | |
55 | 0 | return params.element; |
56 | } | |
57 | }); | |
58 | ||
59 | /** | |
60 | * Click any mouse button (at the coordinates set by the last moveto command). | |
61 | * Note that calling this command after calling buttondown and before calling button up | |
62 | * (or any out-of-order interactions sequence) will yield undefined behaviour). | |
63 | * | |
64 | * @method buttonClick | |
65 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/click | |
66 | * @param {GET} sessionId ID of the session to route the command to | |
67 | * @param {POST} button Which button, enum: {LEFT = 0, MIDDLE = 1 , RIGHT = 2}. Defaults to the left mouse button if not specified. | |
68 | */ | |
69 | ||
70 | // FIXME: rename button* commands to pointerClick, pointerDown, etc. | |
71 | 1 | Driver.addCommand({ |
72 | name: 'buttonClick', | |
73 | url: '/session/:sessionId/click', | |
74 | method: 'POST', | |
75 | params: ['button'] | |
76 | }); | |
77 | ||
78 | /** | |
79 | * Click and hold the left mouse button (at the coordinates set by the last moveto command). | |
80 | * Note that the next mouse-related command that should follow is buttonup. | |
81 | * Any other mouse command (such as click or another call to buttondown) will yield undefined behaviour. | |
82 | * | |
83 | * @method buttondown | |
84 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/buttondown | |
85 | * @param {GET} sessionId ID of the session to route the command to | |
86 | * @param {POST} button Which button, enum: {LEFT = 0, MIDDLE = 1 , RIGHT = 2}. Defaults to the left mouse button if not specified. | |
87 | */ | |
88 | ||
89 | 1 | Driver.addCommand({ |
90 | name: 'buttondown', | |
91 | url: '/session/:sessionId/buttondown', | |
92 | method: 'POST', | |
93 | params: ['button'] | |
94 | }); | |
95 | ||
96 | /** | |
97 | * Releases the mouse button previously held (where the mouse is currently at). | |
98 | * Must be called once for every buttondown command issued. | |
99 | * See the note in click and buttondown about implications of out-of-order commands. | |
100 | * | |
101 | * @method buttonup | |
102 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/buttonup | |
103 | * @param {GET} sessionId ID of the session to route the command to | |
104 | * @param {POST} button Which button, enum: {LEFT = 0, MIDDLE = 1 , RIGHT = 2}. Defaults to the left mouse button if not specified. | |
105 | */ | |
106 | ||
107 | 1 | Driver.addCommand({ |
108 | name: 'buttonup', | |
109 | url: '/session/:sessionId/buttonup', | |
110 | method: 'POST', | |
111 | params: ['button'] | |
112 | }); | |
113 | ||
114 | /** | |
115 | * Double-clicks at the current mouse coordinates (set by moveto). | |
116 | * | |
117 | * @method doubleclickPage | |
118 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/doubleclick | |
119 | * @param {GET} sessionId ID of the session to route the command to | |
120 | */ | |
121 | ||
122 | 1 | Driver.addCommand({ |
123 | name: 'buttonDoubleclick', | |
124 | url: '/session/:sessionId/doubleclick', | |
125 | method: 'POST' | |
126 | }); | |
127 | ||
128 | /** | |
129 | * Single tap on the touch enabled device. | |
130 | * | |
131 | * @method tap | |
132 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/touch/click | |
133 | * @param {GET} sessionId ID of the session to route the command to | |
134 | */ | |
135 | ||
136 | // FIXME: rename touch* and tap commands to touchDown, touchUp, touchFlich, etc. | |
137 | 1 | Driver.addCommand({ |
138 | name: 'tap', | |
139 | url: '/session/:sessionId/touch/click', | |
140 | method: 'POST' | |
141 | }); | |
142 | ||
143 | /** | |
144 | * Finger down on the screen. | |
145 | * | |
146 | * @method touchdown | |
147 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/touch/down | |
148 | * @param {GET} sessionId ID of the session to route the command to | |
149 | * @param {POST} x X coordinate on the screen. | |
150 | * @param {POST} y Y coordinate on the screen. | |
151 | */ | |
152 | ||
153 | 1 | Driver.addCommand({ |
154 | name: 'touchdown', | |
155 | url: '/session/:sessionId/touch/down', | |
156 | method: 'POST', | |
157 | params: ['x', 'y'] | |
158 | }); | |
159 | ||
160 | /** | |
161 | * Finger up on the screen. | |
162 | * | |
163 | * @method touchup | |
164 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/touch/up | |
165 | * @param {GET} sessionId ID of the session to route the command to | |
166 | * @param {POST} x X coordinate on the screen. | |
167 | * @param {POST} y Y coordinate on the screen. | |
168 | */ | |
169 | ||
170 | 1 | Driver.addCommand({ |
171 | name: 'touchup', | |
172 | url: '/session/:sessionId/touch/up', | |
173 | method: 'POST', | |
174 | params: ['x', 'y'] | |
175 | }); | |
176 | ||
177 | /** | |
178 | * Finger move on the screen. | |
179 | * | |
180 | * @method touchmove | |
181 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/touch/move | |
182 | * @param {GET} sessionId ID of the session to route the command to | |
183 | * @param {POST} x X coordinate on the screen. | |
184 | * @param {POST} y Y coordinate on the screen. | |
185 | */ | |
186 | ||
187 | 1 | Driver.addCommand({ |
188 | name: 'touchmove', | |
189 | url: 'session/:sessionId/touch/move', | |
190 | method: 'POST', | |
191 | params: ['x', 'y'] | |
192 | }); | |
193 | ||
194 | /** | |
195 | * Scroll on the touch screen using finger based motion events. | |
196 | * Use this command if you don't care where the scroll starts on the screen. | |
197 | * | |
198 | * @method touchscroll | |
199 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/touch/scroll | |
200 | * @param {GET} sessionId ID of the session to route the command to | |
201 | * @param {POST} x X coordinate on the screen. | |
202 | * @param {POST} y Y coordinate on the screen. | |
203 | */ | |
204 | ||
205 | 1 | Driver.addCommand({ |
206 | name: 'touchscroll', | |
207 | url: 'session/:sessionId/touch/scroll', | |
208 | method: 'POST', | |
209 | params: ['x', 'y'] | |
210 | }); | |
211 | ||
212 | /** | |
213 | * Double tap on the touch screen using finger motion events. | |
214 | * | |
215 | * @method doubletap | |
216 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/touch/doubleclick | |
217 | * @param {GET} sessionId ID of the session to route the command to | |
218 | */ | |
219 | ||
220 | 1 | Driver.addCommand({ |
221 | name: 'doubleTap', | |
222 | url: 'session/:sessionId/touch/doubleclick', | |
223 | method: 'POST' | |
224 | }); | |
225 | ||
226 | /** | |
227 | * Long press on the touch screen using finger motion events. | |
228 | * | |
229 | * @method longpress | |
230 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/touch/longclick | |
231 | * @param {GET} sessionId ID of the session to route the command to | |
232 | */ | |
233 | ||
234 | 1 | Driver.addCommand({ |
235 | name: 'longpress', | |
236 | url: 'session/:sessionId/touch/longclick', | |
237 | method: 'POST' | |
238 | }); | |
239 | ||
240 | /** | |
241 | * Flick on the touch screen using finger motion events. | |
242 | * This flickcommand starts at a particulat screen location. | |
243 | * | |
244 | * @method flick | |
245 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/touch/flick | |
246 | * @param {GET} sessionId ID of the session to route the command to | |
247 | * @param {POST} element ID of the element where the flick starts | |
248 | * @param {POST} xoffset The x offset in pixels to flick by | |
249 | * @param {POST} yoffset The y offset in pixels to flick by | |
250 | * @param {POST} speed The speed in pixels per seconds | |
251 | */ | |
252 | ||
253 | 1 | Driver.addCommand({ |
254 | name: 'flick', | |
255 | url: 'session/:sessionId/touch/flick', | |
256 | method: 'POST', | |
257 | params: ['id', 'x', 'y', 'speed'] | |
258 | }); | |
259 | ||
260 | ||
261 | 1 | Driver.addCommand({ |
262 | url: '/session/:sessionId/keys', | |
263 | method: 'GET' | |
264 | }); | |
265 | ||
266 | }; | |
267 |
Line | Hits | Source |
---|---|---|
1 | /*! | |
2 | * | |
3 | * Copyright (c) 2013 Sebastian Golasch | |
4 | * | |
5 | * Permission is hereby granted, free of charge, to any person obtaining a | |
6 | * copy of this software and associated documentation files (the "Software"), | |
7 | * to deal in the Software without restriction, including without limitation | |
8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
9 | * and/or sell copies of the Software, and to permit persons to whom the | |
10 | * Software is furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included | |
13 | * in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
21 | * DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | ||
25 | /** | |
26 | * Page information related Webdriver endpoints | |
27 | * | |
28 | * @param {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
29 | * @return {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
30 | */ | |
31 | ||
32 | 1 | module.exports = function (Driver) { |
33 | 1 | 'use strict'; |
34 | ||
35 | /** | |
36 | * Get the current page source | |
37 | * | |
38 | * @method source | |
39 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/title | |
40 | * @param {GET} sessionId ID of the session to route the command to | |
41 | */ | |
42 | ||
43 | 1 | Driver.addCommand({ |
44 | name: 'source', | |
45 | url: '/session/:sessionId/source', | |
46 | method: 'GET' | |
47 | }); | |
48 | ||
49 | /** | |
50 | * Get the current page title | |
51 | * | |
52 | * @method title | |
53 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/title | |
54 | * @param {GET} sessionId ID of the session to route the command to | |
55 | */ | |
56 | ||
57 | 1 | Driver.addCommand({ |
58 | name: 'title', | |
59 | url: '/session/:sessionId/title', | |
60 | method: 'GET' | |
61 | }); | |
62 | ||
63 | /** | |
64 | * Checks the device orientation | |
65 | * | |
66 | * @method orientation | |
67 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/orientation | |
68 | * @param {GET} sessionId ID of the session to route the command to | |
69 | */ | |
70 | ||
71 | 1 | Driver.addCommand({ |
72 | url: '/session/:sessionId/orientation', | |
73 | method: 'GET' | |
74 | }); | |
75 | ||
76 | /** | |
77 | * Checks a prompt text | |
78 | * | |
79 | * @method alertText | |
80 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/alert_text | |
81 | * @param {GET} sessionId ID of the session to route the command to | |
82 | */ | |
83 | ||
84 | 1 | Driver.addCommand({ |
85 | name: 'alertText', | |
86 | url: '/session/:sessionId/alert_text', | |
87 | method: 'GET' | |
88 | }); | |
89 | ||
90 | /** | |
91 | * Sets a prompt text | |
92 | * | |
93 | * @method promptText | |
94 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/alert_text | |
95 | * @param {GET} sessionId ID of the session to route the command to | |
96 | * @param {POST} text Text to set | |
97 | */ | |
98 | ||
99 | 1 | Driver.addCommand({ |
100 | name: 'promptText', | |
101 | url: '/session/:sessionId/alert_text', | |
102 | method: 'POST', | |
103 | params: ['text'] | |
104 | }); | |
105 | ||
106 | /** | |
107 | * Accept an dialog box | |
108 | * | |
109 | * @method acceptAlert | |
110 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/accept_alert | |
111 | * @param {GET} sessionId ID of the session to route the command to | |
112 | */ | |
113 | ||
114 | 1 | Driver.addCommand({ |
115 | name: 'acceptAlert', | |
116 | url: '/session/:sessionId/accept_alert', | |
117 | method: 'POST' | |
118 | }); | |
119 | ||
120 | /** | |
121 | * Cancel an dialog box | |
122 | * | |
123 | * @method dismissAlert | |
124 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/dismiss_alert | |
125 | * @param {GET} sessionId ID of the session to route the command to | |
126 | */ | |
127 | ||
128 | 1 | Driver.addCommand({ |
129 | name: 'dismissAlert', | |
130 | url: '/session/:sessionId/dismiss_alert', | |
131 | method: 'POST' | |
132 | }); | |
133 | ||
134 | /** | |
135 | * Get the current geo location | |
136 | * | |
137 | * @method geoLocation | |
138 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/location | |
139 | * @param {GET} sessionId ID of the session to route the command to | |
140 | */ | |
141 | ||
142 | 1 | Driver.addCommand({ |
143 | name: 'geoLocation', | |
144 | url: '/session/:sessionId/location', | |
145 | method: 'GET' | |
146 | }); | |
147 | ||
148 | /** | |
149 | * Set the geo location | |
150 | * | |
151 | * @method setGeoLocation | |
152 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/location | |
153 | * @param {GET} sessionId ID of the session to route the command to | |
154 | * @param {POST} latitude The new location | |
155 | * @param {POST} longitude The new location | |
156 | * @param {POST} altitude The new location | |
157 | */ | |
158 | ||
159 | 1 | Driver.addCommand({ |
160 | name: 'setGeoLocation', | |
161 | url: '/session/:sessionId/location', | |
162 | method: 'POST', | |
163 | params: ['latitude', 'longitude', 'altitude'] | |
164 | }); | |
165 | ||
166 | /** | |
167 | * Get the log for a given log type. | |
168 | * Log buffer is reset after each request. | |
169 | * | |
170 | * @method log | |
171 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/log | |
172 | * @param {GET} sessionId ID of the session to route the command to | |
173 | */ | |
174 | ||
175 | 1 | Driver.addCommand({ |
176 | name: 'log', | |
177 | url: '/session/:sessionId/log', | |
178 | method: 'GET' | |
179 | }); | |
180 | ||
181 | /** | |
182 | * Get available log types | |
183 | * | |
184 | * @method logTypes | |
185 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/log/types | |
186 | * @param {GET} sessionId ID of the session to route the command to | |
187 | */ | |
188 | ||
189 | 1 | Driver.addCommand({ |
190 | name: 'logTypes', | |
191 | url: '/session/:sessionId/log/types', | |
192 | method: 'GET' | |
193 | }); | |
194 | ||
195 | }; | |
196 |
Line | Hits | Source |
---|---|---|
1 | /*! | |
2 | * | |
3 | * Copyright (c) 2013 Sebastian Golasch | |
4 | * | |
5 | * Permission is hereby granted, free of charge, to any person obtaining a | |
6 | * copy of this software and associated documentation files (the "Software"), | |
7 | * to deal in the Software without restriction, including without limitation | |
8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
9 | * and/or sell copies of the Software, and to permit persons to whom the | |
10 | * Software is furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included | |
13 | * in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
21 | * DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | ||
25 | /** | |
26 | * Screenshot related Webdriver endpoints | |
27 | * | |
28 | * @param {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
29 | * @return {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
30 | */ | |
31 | ||
32 | 1 | module.exports = function (Driver) { |
33 | 1 | 'use strict'; |
34 | ||
35 | /** | |
36 | * Take a screenshot of the current page. | |
37 | * | |
38 | * @method screenshot | |
39 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/screenshot | |
40 | * @param {GET} sessionId ID of the session to route the command to | |
41 | */ | |
42 | ||
43 | 1 | Driver.addCommand({ |
44 | name: 'screenshot', | |
45 | url: '/session/:sessionId/screenshot', | |
46 | method: 'GET' | |
47 | }); | |
48 | ||
49 | 1 | return Driver; |
50 | }; | |
51 |
Line | Hits | Source |
---|---|---|
1 | /*! | |
2 | * | |
3 | * Copyright (c) 2013 Sebastian Golasch | |
4 | * | |
5 | * Permission is hereby granted, free of charge, to any person obtaining a | |
6 | * copy of this software and associated documentation files (the "Software"), | |
7 | * to deal in the Software without restriction, including without limitation | |
8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
9 | * and/or sell copies of the Software, and to permit persons to whom the | |
10 | * Software is furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included | |
13 | * in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
21 | * DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | ||
25 | /** | |
26 | * Browser session related Webdriver endpoints | |
27 | * | |
28 | * @param {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
29 | * @return {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
30 | */ | |
31 | ||
32 | 1 | module.exports = function (Driver) { |
33 | 1 | 'use strict'; |
34 | ||
35 | /** | |
36 | * Create a new session. The server should attempt to create a session that most closely matches | |
37 | * the desired and required capabilities. Required capabilities have higher priority than | |
38 | * desired capabilities and must be set for the session to be created. | |
39 | * | |
40 | * @method createSession | |
41 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session | |
42 | * @param {POST} desiredCapabilities An object describing the session's desired capabilities. | |
43 | * @param {POST} requiredCapabilities An object describing the session's required capabilities | |
44 | */ | |
45 | ||
46 | 1 | Driver.addCommand({ |
47 | name: 'createSession', | |
48 | url: '/session', | |
49 | method: 'POST', | |
50 | params: ['desiredCapabilities'], | |
51 | onRequest: function (params) { | |
52 | 0 | return params.desiredCapabilities; |
53 | }, | |
54 | onResponse: function (request, remote, options, deferred, rawData) { | |
55 | 0 | if (!request.headers.location) { |
56 | 0 | this.options.sessionId = JSON.parse(rawData).sessionId; |
57 | } else { | |
58 | 0 | this.options.sessionId = request.headers.location.replace('http://' + options.hostname + ':' + options.port + options.path + '/', '').replace('/session/', '').replace('/wd/hub', ''); |
59 | ||
60 | // fix for sauce (no port in url) | |
61 | 0 | if (this.options.sessionId.search('http://') !== -1) { |
62 | 0 | this.options.sessionId = request.headers.location.replace('http://' + options.hostname + options.path + '/', '').replace('/session/', '').replace('/wd/hub', ''); |
63 | } | |
64 | } | |
65 | ||
66 | 0 | deferred.resolve(this); |
67 | } | |
68 | }); | |
69 | ||
70 | /** | |
71 | * Returns a list of the currently active sessions | |
72 | * | |
73 | * @method sessions | |
74 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/sessions | |
75 | */ | |
76 | ||
77 | 1 | Driver.addCommand({ |
78 | name: 'sessions', | |
79 | url: '/sessions', | |
80 | method: 'GET' | |
81 | }); | |
82 | ||
83 | /** | |
84 | * Retrieve the capabilities of the specified session. | |
85 | * | |
86 | * @method session | |
87 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId | |
88 | * @param {GET} sessionId ID of the session to route the command to | |
89 | */ | |
90 | ||
91 | 1 | Driver.addCommand({ |
92 | name: 'sessionInfo', | |
93 | url: '/session/:sessionId', | |
94 | method: 'GET' | |
95 | }); | |
96 | ||
97 | /** | |
98 | * Delete the session. | |
99 | * | |
100 | * @method session | |
101 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId | |
102 | * @param {GET} sessionId ID of the session to route the command to | |
103 | */ | |
104 | ||
105 | 1 | Driver.addCommand({ |
106 | name: 'deleteSession', | |
107 | url: '/session/:sessionId', | |
108 | method: 'DELETE' | |
109 | }); | |
110 | ||
111 | }; | |
112 |
Line | Hits | Source |
---|---|---|
1 | /*! | |
2 | * | |
3 | * Copyright (c) 2013 Sebastian Golasch | |
4 | * | |
5 | * Permission is hereby granted, free of charge, to any person obtaining a | |
6 | * copy of this software and associated documentation files (the "Software"), | |
7 | * to deal in the Software without restriction, including without limitation | |
8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
9 | * and/or sell copies of the Software, and to permit persons to whom the | |
10 | * Software is furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included | |
13 | * in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
21 | * DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | ||
25 | /** | |
26 | * Storage related Webdriver endpoints | |
27 | * | |
28 | * @param {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
29 | * @return {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
30 | */ | |
31 | ||
32 | 1 | module.exports = function (Driver) { |
33 | 1 | 'use strict'; |
34 | ||
35 | /** | |
36 | * Get all keys of the browsers local storage | |
37 | * | |
38 | * @method getLocalStorage | |
39 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/local_storage | |
40 | * @param {GET} sessionId ID of the session to route the command to | |
41 | */ | |
42 | ||
43 | 1 | Driver.addCommand({ |
44 | name: 'getLocalStorage', | |
45 | url: '/session/:sessionId/local_storage', | |
46 | method: 'GET' | |
47 | }); | |
48 | ||
49 | /** | |
50 | * Set the storage item for the given key | |
51 | * | |
52 | * @method setLocalStorage | |
53 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/local_storage | |
54 | * @param {GET} sessionId ID of the session to route the command to | |
55 | * @param {POST} key The key to set | |
56 | * @param {POST} value The value to set | |
57 | */ | |
58 | ||
59 | 1 | Driver.addCommand({ |
60 | name: 'setLocalStorage', | |
61 | url: '/session/:sessionId/local_storage/key/:key', | |
62 | method: 'POST', | |
63 | params: ['key', 'value'] | |
64 | }); | |
65 | ||
66 | /** | |
67 | * Get the number of items in the storage | |
68 | * | |
69 | * @method getLocalStorageSize | |
70 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/local_storage/size | |
71 | * @param {GET} sessionId ID of the session to route the command to | |
72 | */ | |
73 | ||
74 | 1 | Driver.addCommand({ |
75 | name: 'getLocalStorageSize', | |
76 | url: '/session/:sessionId/local_storage/size', | |
77 | method: 'GET' | |
78 | }); | |
79 | ||
80 | /** | |
81 | * Get all keys of the browsers session storage | |
82 | * | |
83 | * @method getSessionStorage | |
84 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/session_storage | |
85 | * @param {GET} sessionId ID of the session to route the command to | |
86 | */ | |
87 | ||
88 | 1 | Driver.addCommand({ |
89 | name: 'getSessionStorage', | |
90 | url: '/session/:sessionId/session_storage', | |
91 | method: 'GET' | |
92 | }); | |
93 | ||
94 | /** | |
95 | * Get the storage item for the given key | |
96 | * | |
97 | * @method getSessionStorageEntry | |
98 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/session_storage/key/:key | |
99 | * @param {GET} sessionId ID of the session to route the command to | |
100 | * @param {GET} key The key to get | |
101 | */ | |
102 | ||
103 | 1 | Driver.addCommand({ |
104 | name: 'getSessionStorageEntry', | |
105 | url: '/session/:sessionId/session_storage/key/:key', | |
106 | method: 'GET' | |
107 | }); | |
108 | ||
109 | /** | |
110 | * Get the number of items in the storage | |
111 | * | |
112 | * @method getSessionStorageSize | |
113 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/session_storage/size | |
114 | * @param {GET} sessionId ID of the session to route the command to | |
115 | */ | |
116 | ||
117 | 1 | Driver.addCommand({ |
118 | name: 'getSessionStorageSize', | |
119 | url: '/session/:sessionId/session_storage/size', | |
120 | method: 'GET' | |
121 | }); | |
122 | ||
123 | /** | |
124 | * Get the status of the html5 application cache. | |
125 | * | |
126 | * @method applicationCacheStatus | |
127 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/application_cache/status | |
128 | * @param {GET} sessionId ID of the session to route the command to | |
129 | */ | |
130 | ||
131 | 1 | Driver.addCommand({ |
132 | name: 'applicationCacheStatus', | |
133 | url: '/session/:sessionId/application_cache/status', | |
134 | method: 'GET' | |
135 | }); | |
136 | ||
137 | 1 | return Driver; |
138 | }; | |
139 |
Line | Hits | Source |
---|---|---|
1 | /*! | |
2 | * | |
3 | * Copyright (c) 2013 Sebastian Golasch | |
4 | * | |
5 | * Permission is hereby granted, free of charge, to any person obtaining a | |
6 | * copy of this software and associated documentation files (the "Software"), | |
7 | * to deal in the Software without restriction, including without limitation | |
8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
9 | * and/or sell copies of the Software, and to permit persons to whom the | |
10 | * Software is furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included | |
13 | * in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
21 | * DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | ||
25 | /** | |
26 | * Timeout related Webdriver endpoints | |
27 | * | |
28 | * @param {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
29 | * @return {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
30 | */ | |
31 | ||
32 | 1 | module.exports = function (Driver) { |
33 | 1 | 'use strict'; |
34 | ||
35 | /** | |
36 | * Configure the amount of time that a particular type of operation can execute for before | |
37 | * they are aborted and a |Timeout| error is returned to the client. | |
38 | * | |
39 | * @method timeouts | |
40 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/timeouts | |
41 | * @param {GET} sessionId ID of the session to route the command to | |
42 | * @param {POST} type The type of operation to set the timeout for. Valid values are: "script" for script timeouts, "implicit" for modifying the implicit wait timeout and "page load" for setting a page load timeout | |
43 | * @param {POST} ms The amount of time to wait, in milliseconds. This value has a lower bound of 0 | |
44 | */ | |
45 | ||
46 | 1 | Driver.addCommand({ |
47 | name: 'timeouts', | |
48 | url: '/session/:sessionId/timeouts', | |
49 | method: 'POST', | |
50 | params: ['type', 'ms'] | |
51 | }); | |
52 | ||
53 | /** | |
54 | * Set the amount of time, in milliseconds, that asynchronous scripts executed by | |
55 | * /session/:sessionId/execute_async are permitted to run before they are aborted | |
56 | * and a |Timeout| error is returned to the client. | |
57 | * | |
58 | * @method asyncScript | |
59 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/timeouts/async_script | |
60 | * @param {GET} sessionId ID of the session to route the command to | |
61 | * @param {POST} ms The amount of time to wait, in milliseconds. This value has a lower bound of 0 | |
62 | */ | |
63 | ||
64 | 1 | Driver.addCommand({ |
65 | name: 'asyncScript', | |
66 | url: '/session/:sessionId/timeouts/async_script', | |
67 | method: 'POST', | |
68 | params: ['timeout'] | |
69 | }); | |
70 | ||
71 | /** | |
72 | * Set the amount of time the driver should wait when searching for elements. | |
73 | * When searching for a single element, the driver should poll the page until an element | |
74 | * is found or the timeout expires, whichever occurs first. When searching for multiple elements, | |
75 | * the driver should poll the page until at least one element is found or the timeout expires, | |
76 | * at which point it should return an empty list. | |
77 | * | |
78 | * @method implicitWait | |
79 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/timeouts/implicit_wait | |
80 | * @param {GET} sessionId ID of the session to route the command to | |
81 | * @param {POST} ms The amount of time to wait, in milliseconds. This value has a lower bound of 0 | |
82 | */ | |
83 | ||
84 | 1 | Driver.addCommand({ |
85 | name: 'implicitWait', | |
86 | url: '/session/:sessionId/timeouts/implicit_wait', | |
87 | method: 'POST', | |
88 | params: ['timeout'], | |
89 | onRequest: function (params) { | |
90 | 0 | return {ms: params.timeout}; |
91 | } | |
92 | }); | |
93 | ||
94 | }; | |
95 |
Line | Hits | Source |
---|---|---|
1 | /*! | |
2 | * | |
3 | * Copyright (c) 2013 Sebastian Golasch | |
4 | * | |
5 | * Permission is hereby granted, free of charge, to any person obtaining a | |
6 | * copy of this software and associated documentation files (the "Software"), | |
7 | * to deal in the Software without restriction, including without limitation | |
8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
9 | * and/or sell copies of the Software, and to permit persons to whom the | |
10 | * Software is furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included | |
13 | * in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
21 | * DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | ||
25 | /** | |
26 | * Url related Webdriver endpoints | |
27 | * | |
28 | * @param {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
29 | * @return {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
30 | */ | |
31 | ||
32 | 1 | module.exports = function (Driver) { |
33 | 1 | 'use strict'; |
34 | ||
35 | /** | |
36 | * Navigate to a new URL | |
37 | * | |
38 | * @method url | |
39 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/url | |
40 | * @param {GET} sessionId ID of the session to route the command to | |
41 | * @param {POST} page The URL to navigate to. | |
42 | */ | |
43 | ||
44 | 1 | Driver.addCommand({ |
45 | name: 'url', | |
46 | url: '/session/:sessionId/url', | |
47 | method: 'POST', | |
48 | params: ['page'], | |
49 | onRequest: function (params) { | |
50 | 0 | return {url: params.page}; |
51 | }, | |
52 | onResponse: function (request, remote, options, deferred) { | |
53 | 0 | deferred.resolve(this); |
54 | } | |
55 | }); | |
56 | ||
57 | /** | |
58 | * Retrieve the URL of the current page | |
59 | * | |
60 | * @method getUrl | |
61 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/url | |
62 | * @param {GET} sessionId ID of the session to route the command to | |
63 | */ | |
64 | ||
65 | 1 | Driver.addCommand({ |
66 | name: 'getUrl', | |
67 | url: '/session/:sessionId/url', | |
68 | method: 'GET' | |
69 | }); | |
70 | ||
71 | /** | |
72 | * Navigate forwards in the browser history, if possible. | |
73 | * | |
74 | * @method forward | |
75 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/forward | |
76 | * @param {GET} sessionId ID of the session to route the command to | |
77 | */ | |
78 | ||
79 | 1 | Driver.addCommand({ |
80 | name: 'forward', | |
81 | url: '/session/:sessionId/forward', | |
82 | method: 'POST' | |
83 | }); | |
84 | ||
85 | /** | |
86 | * Navigate backwards in the browser history, if possible | |
87 | * | |
88 | * @method back | |
89 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/back | |
90 | * @param {GET} sessionId ID of the session to route the command to | |
91 | */ | |
92 | ||
93 | 1 | Driver.addCommand({ |
94 | name: 'back', | |
95 | url: '/session/:sessionId/back', | |
96 | method: 'POST' | |
97 | }); | |
98 | ||
99 | /** | |
100 | * Refresh the current page | |
101 | * | |
102 | * @method refresh | |
103 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/back | |
104 | * @param {GET} sessionId ID of the session to route the command to | |
105 | */ | |
106 | ||
107 | 1 | Driver.addCommand({ |
108 | name: 'refresh', | |
109 | url: '/session/:sessionId/refresh', | |
110 | method: 'GET' | |
111 | }); | |
112 | }; | |
113 |
Line | Hits | Source |
---|---|---|
1 | /*! | |
2 | * | |
3 | * Copyright (c) 2013 Sebastian Golasch | |
4 | * | |
5 | * Permission is hereby granted, free of charge, to any person obtaining a | |
6 | * copy of this software and associated documentation files (the "Software"), | |
7 | * to deal in the Software without restriction, including without limitation | |
8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
9 | * and/or sell copies of the Software, and to permit persons to whom the | |
10 | * Software is furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included | |
13 | * in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
21 | * DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | ||
25 | /** | |
26 | * Window related Webdriver endpoints | |
27 | * | |
28 | * @param {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
29 | * @return {Dalek.Internal.Webdriver} Driver Webdriver client instance | |
30 | */ | |
31 | ||
32 | 1 | module.exports = function (Driver) { |
33 | 1 | 'use strict'; |
34 | ||
35 | /** | |
36 | * Retrieve the current window handle. | |
37 | * | |
38 | * @method windowHandle | |
39 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/window_handle | |
40 | * @param {GET} sessionId ID of the session to route the command to | |
41 | */ | |
42 | ||
43 | 1 | Driver.addCommand({ |
44 | name: 'windowHandle', | |
45 | url: '/session/:sessionId/window_handle', | |
46 | method: 'GET' | |
47 | }); | |
48 | ||
49 | /** | |
50 | * Retrieve the list of all window handles available to the session. | |
51 | * | |
52 | * @method windowHandles | |
53 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/window_handles | |
54 | * @param {GET} sessionId ID of the session to route the command to | |
55 | */ | |
56 | ||
57 | 1 | Driver.addCommand({ |
58 | name: 'windowHandles', | |
59 | url: '/session/:sessionId/window_handles', | |
60 | method: 'GET' | |
61 | }); | |
62 | ||
63 | /** | |
64 | * Change focus to another window. | |
65 | * The window to change focus to may be specified by its server assigned window handle, or by the value of its name attribute. | |
66 | * | |
67 | * @method changeWindow | |
68 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/window | |
69 | * @param {GET} sessionId ID of the session to route the command to | |
70 | * @param {POST} name Name of the window to switch to | |
71 | */ | |
72 | ||
73 | 1 | Driver.addCommand({ |
74 | name: 'changeWindow', | |
75 | url: '/session/:sessionId/window', | |
76 | method: 'POST', | |
77 | params: ['name'] | |
78 | }); | |
79 | ||
80 | /** | |
81 | * Get the size of the specified window. | |
82 | * If the :windowHandle URL parameter is "current", the size of the currently active window will be returned. | |
83 | * | |
84 | * @method getWindowSize | |
85 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/window/:windowHandle/size | |
86 | * @param {GET} sessionId ID of the session to route the command to | |
87 | * @param {GET} windowHandle ID of the window to route the command to | |
88 | */ | |
89 | ||
90 | 1 | Driver.addCommand({ |
91 | name: 'getWindowSize', | |
92 | url: '/session/:sessionId/window/current/size', | |
93 | method: 'GET' | |
94 | }); | |
95 | ||
96 | /** | |
97 | * Change the size of the specified window. | |
98 | * If the :windowHandle URL parameter is "current", | |
99 | * the currently active window will be resized. | |
100 | * | |
101 | * @method setWindowSize | |
102 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/window/:windowHandle/size | |
103 | * @param {POST} sessionId ID of the session to route the command to | |
104 | * @param {POST} windowHandle ID of the window to route the command to | |
105 | * @param {POST} width The new window width | |
106 | * @param {POST} height The new window height | |
107 | */ | |
108 | ||
109 | 1 | Driver.addCommand({ |
110 | name: 'setWindowSize', | |
111 | url: '/session/:sessionId/window/current/size', | |
112 | method: 'POST', | |
113 | params: ['width', 'height'] | |
114 | }); | |
115 | ||
116 | /** | |
117 | * Get the position of the specified window. | |
118 | * If the :windowHandle URL parameter is "current", the position of the currently active window will be returned. | |
119 | * | |
120 | * @method getWindowPosition | |
121 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/window/:windowHandle/position | |
122 | * @param {GET} sessionId ID of the session to route the command to | |
123 | * @param {GET} windowHandle ID of the window to route the command to | |
124 | */ | |
125 | ||
126 | 1 | Driver.addCommand({ |
127 | name: 'getWindowPosition', | |
128 | url: '/session/:sessionId/window/:windowHandle/position', | |
129 | method: 'GET' | |
130 | }); | |
131 | ||
132 | /** | |
133 | * Set the position of the specified window. | |
134 | * | |
135 | * @method setWindowPosition | |
136 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/window/:windowHandle/position | |
137 | * @param {POST} sessionId ID of the session to route the command to | |
138 | * @param {POST} x The X coordinates for the window, relative to the upper left corner of the screen. | |
139 | * @param {POST} y The Y coordinates for the window, relative to the upper left corner of the screen. | |
140 | */ | |
141 | ||
142 | 1 | Driver.addCommand({ |
143 | name: 'setWindowPosition', | |
144 | url: '/session/:sessionId/window/current/position', | |
145 | method: 'POST', | |
146 | params: ['x', 'y'] | |
147 | }); | |
148 | ||
149 | /** | |
150 | * Maximize the specified window if not already maximized. | |
151 | * If the :windowHandle URL parameter is "current", the currently active window will be maximized. | |
152 | * | |
153 | * @method windowMaximize | |
154 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/window/:windowHandle/position | |
155 | * @param {GET} sessionId ID of the session to route the command to | |
156 | * @param {GET} windowHandle ID of the window to route the command to | |
157 | */ | |
158 | ||
159 | 1 | Driver.addCommand({ |
160 | name: 'maximize', | |
161 | url: '/session/:sessionId/window/current/maximize', | |
162 | method: 'POST' | |
163 | }); | |
164 | ||
165 | /** | |
166 | * Closes the current window. | |
167 | * | |
168 | * @method close | |
169 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#DELETE_/session/:sessionId/window | |
170 | * @param {GET} sessionId ID of the session to route the command to | |
171 | */ | |
172 | ||
173 | 1 | Driver.addCommand({ |
174 | name: 'close', | |
175 | url: '/session/:sessionId/window', | |
176 | method: 'DELETE' | |
177 | }); | |
178 | ||
179 | }; | |
180 |
Line | Hits | Source |
---|---|---|
1 | /*! | |
2 | * | |
3 | * Copyright (c) 2013 Sebastian Golasch | |
4 | * | |
5 | * Permission is hereby granted, free of charge, to any person obtaining a | |
6 | * copy of this software and associated documentation files (the "Software"), | |
7 | * to deal in the Software without restriction, including without limitation | |
8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
9 | * and/or sell copies of the Software, and to permit persons to whom the | |
10 | * Software is furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included | |
13 | * in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
21 | * DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | ||
25 | 1 | 'use strict'; |
26 | ||
27 | // ext. libs | |
28 | 1 | var http = require('http'); |
29 | 1 | var Q = require('q'); |
30 | ||
31 | // export the driver base function | |
32 | 1 | module.exports = function exportDriverBase(WebDriver) { |
33 | ||
34 | /** | |
35 | * Native Webdriver base class | |
36 | * | |
37 | * @module DalekJS | |
38 | * @class Driver | |
39 | * @namespace Internal | |
40 | */ | |
41 | ||
42 | 1 | var Driver = { |
43 | ||
44 | /** | |
45 | * Parses an JSON Wire protocol dummy url | |
46 | * | |
47 | * @method parseUrl | |
48 | * @param {string} url URL with placeholders | |
49 | * @param {object} options List of url options | |
50 | * @return {string} url Parsed URL | |
51 | */ | |
52 | ||
53 | parseUrl: function (url, options) { | |
54 | 0 | return Object.keys(options).reduce(this._replacePlaceholderInUrl.bind(this, options), url); |
55 | }, | |
56 | ||
57 | /** | |
58 | * Replaces placeholders in urls | |
59 | * | |
60 | * @method _replacePlaceholderInUrl | |
61 | * @param {object} options List of url options | |
62 | * @param {string} url URL with placeholders | |
63 | * @param {string} option Option to process | |
64 | * @return {string} url Parsed URL | |
65 | * @private | |
66 | */ | |
67 | ||
68 | _replacePlaceholderInUrl: function (options, url, option) { | |
69 | 0 | return url.replace(':' + option, options[option]); |
70 | }, | |
71 | ||
72 | /** | |
73 | * Generates a set of params for the message body of the request | |
74 | * | |
75 | * @method generateParamset | |
76 | * @param {object|null} requestedParams Keys & placeholders for the paramset | |
77 | * @param {object} providedParams Values for the paramset | |
78 | * @return {object} params Params for the message body | |
79 | */ | |
80 | ||
81 | generateParamset: function (requestedParams, providedParams) { | |
82 | 0 | return !requestedParams ? {} : requestedParams.reduce(this._mapParams.bind(this, providedParams), {}); |
83 | }, | |
84 | ||
85 | /** | |
86 | * Mpas object values & keys of two objects | |
87 | * | |
88 | * @method _mapParams | |
89 | * @param {object} providedParams Values for the paramset | |
90 | * @param {object} params The object to be filled | |
91 | * @param {string} param The key of the output object | |
92 | * @param {integer} idx Index of the iteration | |
93 | * @return {object} params Params for the message body | |
94 | * @private | |
95 | */ | |
96 | ||
97 | _mapParams: function (providedParams, params, param, idx) { | |
98 | 0 | params[param] = providedParams[idx]; |
99 | 0 | return params; |
100 | }, | |
101 | ||
102 | /** | |
103 | * Generates the message body for webdriver client requests of type POST | |
104 | * | |
105 | * @method generateBody | |
106 | * @param {object} options Browser options (name, bin path, etc.) | |
107 | * @param {function|undefined} cb Callback function that should be invoked to generate the message body | |
108 | * @param {Dalek.Internal.Webdriver} wd Webdriver base object | |
109 | * @param {object} params Parameters that should be part of the message body | |
110 | * @return {string} body Serialized JSON of body request data | |
111 | */ | |
112 | ||
113 | generateBody: function (options, cb, wd, params) { | |
114 | // if no cb is given, generate a body with the `desiredCapabilities` object | |
115 | 0 | if (!cb) { |
116 | // check if we have parameters set up | |
117 | 0 | if (Object.keys(params).length > 0) { |
118 | 0 | return JSON.stringify(params); |
119 | } | |
120 | 0 | return ''; |
121 | } | |
122 | ||
123 | // invoke the given callback & stringify | |
124 | 0 | var data = cb.call(wd, params); |
125 | 0 | return data === null ? '{}' : JSON.stringify(data); |
126 | }, | |
127 | ||
128 | /** | |
129 | * Generates the request options for a webdriver client request | |
130 | * | |
131 | * @method generateRequestOptions | |
132 | * @param {string} hostname Hostname of the webdriver server | |
133 | * @param {integer} port Port of the webdriver server | |
134 | * @param {string} prefix Url address prefix of the webdriver endpoint | |
135 | * @param {string} url Url of the webdriver method | |
136 | * @param {string} method Request method e.g. (GET, POST, DELETE, PUT) | |
137 | * @param {string} body The message body of the request | |
138 | * @return {object} options Request options | |
139 | */ | |
140 | ||
141 | generateRequestOptions: function (hostname, port, prefix, url, method, body, auth) { | |
142 | 0 | var options = { |
143 | hostname: hostname, | |
144 | port: port, | |
145 | path: prefix + url, | |
146 | method: method, | |
147 | headers: { | |
148 | 'Content-Type': 'application/json;charset=utf-8', | |
149 | 'Content-Length': Buffer.byteLength(body, 'utf8') | |
150 | } | |
151 | }; | |
152 | ||
153 | // check if auth information is available | |
154 | 0 | if (auth) { |
155 | 0 | options.auth = auth; |
156 | } | |
157 | ||
158 | 0 | return options; |
159 | }, | |
160 | ||
161 | /** | |
162 | * Generates a new webdriver client command | |
163 | * Takes a skeleton of obtions that will be converted | |
164 | * into a new function that can be invoked & will issue | |
165 | * a webdriver command to the webdriver server | |
166 | * | |
167 | * @method addCommand | |
168 | * @param {object} remote Object skeleton that will be turned into a webdriver client method | |
169 | * @chainable | |
170 | */ | |
171 | ||
172 | addCommand: function (remote) { | |
173 | // assign the generated function to the webdriver prototype | |
174 | 88 | WebDriver.prototype[remote.name] = this._generateWebdriverCommand(remote, this); |
175 | 88 | return this; |
176 | }, | |
177 | ||
178 | /** | |
179 | * Generates the webdriver callback function | |
180 | * | |
181 | * @method _generateWebdriverCommand | |
182 | * @param {object} remote Dummy request body (function name, url, method) | |
183 | * @param {DalekJs.Internal.Driver} driver Driver instance | |
184 | * @return {function} webdriverCommand Generated webdriver command function | |
185 | * @private | |
186 | */ | |
187 | ||
188 | _generateWebdriverCommand: function (remote, driver) { | |
189 | 88 | return function webdriverCommand() { |
190 | 0 | var deferred = Q.defer(); |
191 | // the request meta data | |
192 | 0 | var params = Driver.generateParamset(remote.params, arguments); |
193 | 0 | var body = Driver.generateBody({}, remote.onRequest, this, params); |
194 | 0 | var options = Driver.generateRequestOptions(this.opts.host, this.opts.port, this.opts.path, Driver.parseUrl(remote.url, this.options), remote.method, body, this.opts.auth); |
195 | ||
196 | // generate the request, wait for response & fire the request | |
197 | 0 | var req = new http.ClientRequest(options); |
198 | 0 | req.on('response', driver._onResponse.bind(this, driver, remote, options, deferred)); |
199 | 0 | req.end(body); |
200 | ||
201 | 0 | return deferred.promise; |
202 | }; | |
203 | }, | |
204 | ||
205 | /** | |
206 | * Response callback function | |
207 | * | |
208 | * @method _onResponse | |
209 | * @param {DalekJs.Internal.Driver} driver Driver instance | |
210 | * @param {object} remote Dummy request body (function name, url, method) | |
211 | * @param {object} options Request options (method, port, path, headers, etc.) | |
212 | * @param {object} deferred Webdriver command deferred | |
213 | * @param {object} response Response from the webdriver server | |
214 | * @chainable | |
215 | * @private | |
216 | */ | |
217 | ||
218 | _onResponse: function (driver, remote, options, deferred, response) { | |
219 | 0 | this.data = ''; |
220 | 0 | response.on('data', driver._concatDataChunks.bind(this)); |
221 | 0 | response.on('end', driver._onResponseEnd.bind(this, driver, response, remote, options, deferred)); |
222 | 0 | return this; |
223 | }, | |
224 | ||
225 | /** | |
226 | * Concatenates chunks of strings | |
227 | * | |
228 | * @method _concatDataChunks | |
229 | * @param {string} chunk String to add | |
230 | * @return {string} data Concatenated string | |
231 | * @private | |
232 | */ | |
233 | ||
234 | _concatDataChunks: function (chunk) { | |
235 | 0 | return this.data += chunk; |
236 | }, | |
237 | ||
238 | /** | |
239 | * Response end callback function | |
240 | * | |
241 | * @method _onResponseEnd | |
242 | * @param {DalekJs.Internal.Driver} driver Driver instance | |
243 | * @param {object} response Response from the webdriver server | |
244 | * @param {object} remote Dummy request body (function name, url, method) | |
245 | * @param {object} options Request options (method, port, path, headers, etc.) | |
246 | * @param {object} deferred Webdriver command deferred | |
247 | * @chainable | |
248 | * @priavte | |
249 | */ | |
250 | ||
251 | _onResponseEnd: function (driver, response, remote, options, deferred) { | |
252 | 0 | return driver[(response.statusCode === 500 ? '_onError' : '_onSuccess')].bind(this)(driver, response, remote, options, deferred); |
253 | }, | |
254 | ||
255 | /** | |
256 | * On error callback function | |
257 | * | |
258 | * @method _onError | |
259 | * @param {DalekJs.Internal.Driver} driver Driver instance | |
260 | * @param {object} response Response from the webdriver server | |
261 | * @param {object} remote Dummy request body (function name, url, method) | |
262 | * @param {object} options Request options (method, port, path, headers, etc.) | |
263 | * @param {object} deferred Webdriver command deferred | |
264 | * @chainable | |
265 | * @private | |
266 | */ | |
267 | ||
268 | _onError: function (driver, response, remote, options, deferred) { | |
269 | // Provide a default error handler to prevent hangs. | |
270 | 0 | if (!remote.onError) { |
271 | 0 | remote.onError = function (request, remote, options, deferred, data) { |
272 | 0 | data = JSON.parse(data); |
273 | 0 | var value = -1; |
274 | 0 | if (typeof data.value.message === 'string') { |
275 | 0 | var msg = JSON.parse(data.value.message); |
276 | 0 | value = msg.errorMessage; |
277 | } | |
278 | 0 | deferred.resolve(JSON.stringify({'sessionId': data.sessionId, value: value})); |
279 | }; | |
280 | } | |
281 | 0 | remote.onError.call(this, response, remote, options, deferred, this.data); |
282 | 0 | return this; |
283 | }, | |
284 | ||
285 | /** | |
286 | * On success callback function | |
287 | * | |
288 | * @method _onSuccess | |
289 | * @param {DalekJs.Internal.Driver} driver Driver instance | |
290 | * @param {object} response Response from the webdriver server | |
291 | * @param {object} remote Dummy request body (function name, url, method) | |
292 | * @param {object} options Request options (method, port, path, headers, etc.) | |
293 | * @param {object} deferred Webdriver command deferred | |
294 | * @chainable | |
295 | * @private | |
296 | */ | |
297 | ||
298 | _onSuccess: function (driver, response, remote, options, deferred) { | |
299 | // log response data | |
300 | 0 | this.events.emit('driver:webdriver:response', { |
301 | statusCode: response.statusCode, | |
302 | method: response.req.method, | |
303 | path: response.req.path, | |
304 | data: this.data | |
305 | }); | |
306 | ||
307 | 0 | if (remote.onResponse) { |
308 | 0 | remote.onResponse.call(this, response, remote, options, deferred, this.data); |
309 | } else { | |
310 | 0 | deferred.resolve(this.data); |
311 | } | |
312 | 0 | return this; |
313 | } | |
314 | }; | |
315 | ||
316 | 1 | return Driver; |
317 | }; | |
318 |
Line | Hits | Source |
---|---|---|
1 | /*! | |
2 | * | |
3 | * Copyright (c) 2013 Sebastian Golasch | |
4 | * | |
5 | * Permission is hereby granted, free of charge, to any person obtaining a | |
6 | * copy of this software and associated documentation files (the "Software"), | |
7 | * to deal in the Software without restriction, including without limitation | |
8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
9 | * and/or sell copies of the Software, and to permit persons to whom the | |
10 | * Software is furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included | |
13 | * in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
21 | * DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | ||
25 | 1 | 'use strict'; |
26 | ||
27 | /** | |
28 | * Stores the injected options as an object property | |
29 | * | |
30 | * @param {object} opts Webdriver options | |
31 | * @constructor | |
32 | */ | |
33 | ||
34 | 1 | var WebDriver = function (opts, events) { |
35 | 0 | this.events = events; |
36 | 0 | this.opts = opts; |
37 | }; | |
38 | ||
39 | /** | |
40 | * Webdriver base class | |
41 | * | |
42 | * @namespace Internal | |
43 | * @module DalekJS | |
44 | * @class Webdriver | |
45 | */ | |
46 | ||
47 | 1 | WebDriver.prototype = { |
48 | ||
49 | /** | |
50 | * Local options, used to store data | |
51 | * like the current sessionId or similar | |
52 | */ | |
53 | ||
54 | options: {}, | |
55 | ||
56 | /** | |
57 | * Checks if we have a valid webdriver session | |
58 | * | |
59 | * @method hasSession | |
60 | * @return {bool} Is valid session | |
61 | */ | |
62 | ||
63 | hasSession: function () { | |
64 | 0 | return !!this.options.sessionId; |
65 | }, | |
66 | ||
67 | /** | |
68 | * Closes the current webdriver session | |
69 | * | |
70 | * @method hasSession | |
71 | * @chainable | |
72 | */ | |
73 | ||
74 | closeSession: function () { | |
75 | 0 | delete this.options.sessionId; |
76 | 0 | return this; |
77 | } | |
78 | }; | |
79 | ||
80 | // export the module | |
81 | 1 | module.exports = WebDriver; |
82 |