Coverage

62%
221
138
83

/home/ubuntu/src/github.com/dalekjs/dalek-internal-webdriver/index.js

100%
8
8
0
LineHitsSource
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
251'use strict';
26
27/**
28 * Its a webdriver client
29 *
30 * @part Webdriver
31 * @api
32 */
33
34// ext. libs
351var fs = require('fs');
36
37// int. libs
381var WebDriver = require('./lib/webdriver');
391var Driver = require('./lib/driver')(WebDriver);
40
41// include webdriver commands
421var dir = __dirname + '/lib/commands/';
431fs.readdirSync(dir).forEach(function (file) {
4413 require(dir + file)(Driver);
45});
46
47// export the webdriver module
481module.exports = WebDriver;
49

/home/ubuntu/src/github.com/dalekjs/dalek-internal-webdriver/lib/commands/cookie.js

100%
6
6
0
LineHitsSource
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
321module.exports = function (Driver) {
331 '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
431 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
581 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
761 Driver.addCommand({
77 name: 'setCookie',
78 url: '/session/:sessionId/cookie',
79 method: 'POST',
80 params: ['cookie']
81 });
82
831 return Driver;
84};
85

/home/ubuntu/src/github.com/dalekjs/dalek-internal-webdriver/lib/commands/element.js

58%
41
24
17
LineHitsSource
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
321module.exports = function (Driver) {
331 '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
451 Driver.addCommand({
46 name: 'element',
47 url: '/session/:sessionId/element',
48 method: 'POST',
49 params: ['selector'],
50 onRequest: function (params) {
510 var type = 'css selector';
520 return {using: type, value: params.selector};
53 },
54 onResponse: function (request, remote, options, deferred, data) {
550 this.options.id = JSON.parse(data).value.ELEMENT;
560 deferred.resolve(data);
57 },
58 onError: function (request, remote, options, deferred, data) {
590 data = JSON.parse(data);
600 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
741 Driver.addCommand({
75 name: 'elements',
76 url: '/session/:sessionId/elements',
77 method: 'POST',
78 params: ['selector'],
79 onRequest: function (params) {
800 var type = 'css selector';
810 return {using: type, value: params.selector};
82 },
83 onResponse: function (request, remote, options, deferred, data) {
840 deferred.resolve(data);
85 },
86 onError: function (request, remote, options, deferred, data) {
870 data = JSON.parse(data);
880 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
1021 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
1171 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
1371 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
1571 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
1711 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
1871 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
2021 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
2181 Driver.addCommand({
219 name: 'val',
220 url: '/session/:sessionId/element/:id/value',
221 method: 'POST',
222 params: ['text'],
223 onRequest: function (params) {
2240 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
2371 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
2521 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
2671 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
2821 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
2981 Driver.addCommand({
299 name: 'getAttribute',
300 url: '/session/:sessionId/element/:id/attribute/:name',
301 method: 'GET',
302 params: ['name'],
303 onRequest: function (params) {
3040 this.options.name = params.name;
3050 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
3191 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
3351 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
3511 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
3671 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
3831 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
4011 Driver.addCommand({
402 name: 'cssProperty',
403 url: '/session/:sessionId/element/:id/css/:propertyName',
404 method: 'GET',
405 params: ['propertyName'],
406 onRequest: function (params) {
4070 this.options.propertyName = params.propertyName;
4080 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
4231 Driver.addCommand({
424 name: 'sendKeys',
425 url: '/session/:sessionId/keys',
426 method: 'POST',
427 params: ['text'],
428 onRequest: function (params) {
4290 return {value: params.text.split('')};
430 }
431 });
432
433};
434

/home/ubuntu/src/github.com/dalekjs/dalek-internal-webdriver/lib/commands/execute.js

41%
12
5
7
LineHitsSource
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
261var 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
351module.exports = function (Driver) {
361 '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
531 Driver.addCommand({
54 name: 'execute',
55 url: '/session/:sessionId/execute',
56 method: 'POST',
57 params: ['script', 'arguments'],
58 onRequest: function (raw) {
590 var script = raw.script.script.replace(/\\n/g, ' ').replace(/\\t/g, ' ');
600 var userArgs = script.substring(script.indexOf('(') + 1, script.indexOf(')'));
610 var dalekScript = String(fs.readFileSync(fs.realpathSync(__dirname + '/../browser/script.js')));
62
630 var userscript = script.substring(script.indexOf('{') + 1, script.lastIndexOf('}'));
640 script = dalekScript.replace('__USERARGUMENTS', userArgs);
650 script = script.replace('__SCRIPT;', userscript);
66
670 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
901 Driver.addCommand({
91 name: 'executeAsync',
92 url: '/session/:sessionId/execute_async',
93 method: 'POST',
94 params: ['script', 'arguments']
95 });
96
97};
98

/home/ubuntu/src/github.com/dalekjs/dalek-internal-webdriver/lib/commands/frame.js

33%
9
3
6
LineHitsSource
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
321module.exports = function (Driver) {
331 '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
451 Driver.addCommand({
46 name: 'frame',
47 url: '/session/:sessionId/frame',
48 method: 'POST',
49 params: ['id'],
50 onRequest: function (elementRaw) {
510 var id = null;
520 try {
530 var element = JSON.parse(elementRaw.id);
540 id = (element.value && element.value.ELEMENT) ? element.value : null;
55 } catch (e) {
560 id = null;
57 }
580 return {id: id};
59 }
60 });
61
62};
63

/home/ubuntu/src/github.com/dalekjs/dalek-internal-webdriver/lib/commands/ime.js

100%
8
8
0
LineHitsSource
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
321module.exports = function (Driver) {
331 '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
471 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
621 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
771 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
911 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
1051 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
1241 Driver.addCommand({
125 name: 'activateEngine',
126 url: '/session/:sessionId/ime/activate',
127 method: 'POST',
128 params: ['engine']
129 });
130
131};
132

/home/ubuntu/src/github.com/dalekjs/dalek-internal-webdriver/lib/commands/interaction.js

94%
17
16
1
LineHitsSource
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
321module.exports = function (Driver) {
331 '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
491 Driver.addCommand({
50 name: 'moveto',
51 url: '/session/:sessionId/moveto',
52 method: 'POST',
53 params: ['element', 'xoffset', 'yoffset'],
54 onRequest: function (params) {
550 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.
711 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
891 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
1071 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
1221 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.
1371 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
1531 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
1701 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
1871 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
2051 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
2201 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
2341 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
2531 Driver.addCommand({
254 name: 'flick',
255 url: 'session/:sessionId/touch/flick',
256 method: 'POST',
257 params: ['id', 'x', 'y', 'speed']
258 });
259
260
2611 Driver.addCommand({
262 url: '/session/:sessionId/keys',
263 method: 'GET'
264 });
265
266};
267

/home/ubuntu/src/github.com/dalekjs/dalek-internal-webdriver/lib/commands/page.js

100%
13
13
0
LineHitsSource
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
321module.exports = function (Driver) {
331 '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
431 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
571 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
711 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
841 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
991 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
1141 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
1281 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
1421 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
1591 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
1751 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
1891 Driver.addCommand({
190 name: 'logTypes',
191 url: '/session/:sessionId/log/types',
192 method: 'GET'
193 });
194
195};
196

/home/ubuntu/src/github.com/dalekjs/dalek-internal-webdriver/lib/commands/screenshot.js

100%
4
4
0
LineHitsSource
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
321module.exports = function (Driver) {
331 '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
431 Driver.addCommand({
44 name: 'screenshot',
45 url: '/session/:sessionId/screenshot',
46 method: 'GET'
47 });
48
491 return Driver;
50};
51

/home/ubuntu/src/github.com/dalekjs/dalek-internal-webdriver/lib/commands/session.js

46%
13
6
7
LineHitsSource
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
321module.exports = function (Driver) {
331 '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
461 Driver.addCommand({
47 name: 'createSession',
48 url: '/session',
49 method: 'POST',
50 params: ['desiredCapabilities'],
51 onRequest: function (params) {
520 return params.desiredCapabilities;
53 },
54 onResponse: function (request, remote, options, deferred, rawData) {
550 if (!request.headers.location) {
560 this.options.sessionId = JSON.parse(rawData).sessionId;
57 } else {
580 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)
610 if (this.options.sessionId.search('http://') !== -1) {
620 this.options.sessionId = request.headers.location.replace('http://' + options.hostname + options.path + '/', '').replace('/session/', '').replace('/wd/hub', '');
63 }
64 }
65
660 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
771 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
911 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
1051 Driver.addCommand({
106 name: 'deleteSession',
107 url: '/session/:sessionId',
108 method: 'DELETE'
109 });
110
111};
112

/home/ubuntu/src/github.com/dalekjs/dalek-internal-webdriver/lib/commands/storage.js

100%
10
10
0
LineHitsSource
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
321module.exports = function (Driver) {
331 '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
431 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
591 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
741 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
881 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
1031 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
1171 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
1311 Driver.addCommand({
132 name: 'applicationCacheStatus',
133 url: '/session/:sessionId/application_cache/status',
134 method: 'GET'
135 });
136
1371 return Driver;
138};
139

/home/ubuntu/src/github.com/dalekjs/dalek-internal-webdriver/lib/commands/timeout.js

83%
6
5
1
LineHitsSource
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
321module.exports = function (Driver) {
331 '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
461 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
641 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
841 Driver.addCommand({
85 name: 'implicitWait',
86 url: '/session/:sessionId/timeouts/implicit_wait',
87 method: 'POST',
88 params: ['timeout'],
89 onRequest: function (params) {
900 return {ms: params.timeout};
91 }
92 });
93
94};
95

/home/ubuntu/src/github.com/dalekjs/dalek-internal-webdriver/lib/commands/url.js

77%
9
7
2
LineHitsSource
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
321module.exports = function (Driver) {
331 '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
441 Driver.addCommand({
45 name: 'url',
46 url: '/session/:sessionId/url',
47 method: 'POST',
48 params: ['page'],
49 onRequest: function (params) {
500 return {url: params.page};
51 },
52 onResponse: function (request, remote, options, deferred) {
530 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
651 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
791 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
931 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
1071 Driver.addCommand({
108 name: 'refresh',
109 url: '/session/:sessionId/refresh',
110 method: 'GET'
111 });
112};
113

/home/ubuntu/src/github.com/dalekjs/dalek-internal-webdriver/lib/commands/window.js

100%
10
10
0
LineHitsSource
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
321module.exports = function (Driver) {
331 '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
431 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
571 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
731 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
901 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 {GET} sessionId ID of the session to route the command to
104 * @param {GET} 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
1091 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
1261 Driver.addCommand({
127 name: 'getWindowPosition',
128 url: '/session/:sessionId/window/:windowHandle/position',
129 method: 'GET'
130 });
131
132 /**
133 * Maximize the specified window if not already maximized.
134 * If the :windowHandle URL parameter is "current", the currently active window will be maximized.
135 *
136 * @method windowMaximize
137 * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/window/:windowHandle/position
138 * @param {GET} sessionId ID of the session to route the command to
139 * @param {GET} windowHandle ID of the window to route the command to
140 */
141
1421 Driver.addCommand({
143 name: 'maximize',
144 url: '/session/:sessionId/window/current/maximize',
145 method: 'POST'
146 });
147
148 /**
149 * Closes the current window.
150 *
151 * @method close
152 * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#DELETE_/session/:sessionId/window
153 * @param {GET} sessionId ID of the session to route the command to
154 */
155
1561 Driver.addCommand({
157 name: 'close',
158 url: '/session/:sessionId/window',
159 method: 'DELETE'
160 });
161
162};
163

/home/ubuntu/src/github.com/dalekjs/dalek-internal-webdriver/lib/driver.js

19%
46
9
37
LineHitsSource
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
251'use strict';
26
27// ext. libs
281var http = require('http');
291var Q = require('q');
30
31// export the driver base function
321module.exports = function exportDriverBase(WebDriver) {
33
34 /**
35 * Native Webdriver base class
36 *
37 * @module DalekJS
38 * @class Driver
39 * @namespace Internal
40 */
41
421 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) {
540 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) {
690 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) {
820 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) {
980 params[param] = providedParams[idx];
990 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
1150 if (!cb) {
116 // check if we have parameters set up
1170 if (Object.keys(params).length > 0) {
1180 return JSON.stringify(params);
119 }
1200 return '';
121 }
122
123 // invoke the given callback & stringify
1240 var data = cb.call(wd, params);
1250 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) {
1420 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
1540 if (auth) {
1550 options.auth = auth;
156 }
157
1580 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
17487 WebDriver.prototype[remote.name] = this._generateWebdriverCommand(remote, this);
17587 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) {
18987 return function webdriverCommand() {
1900 var deferred = Q.defer();
191 // the request meta data
1920 var params = Driver.generateParamset(remote.params, arguments);
1930 var body = Driver.generateBody({}, remote.onRequest, this, params);
1940 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
1970 var req = new http.ClientRequest(options);
1980 req.on('response', driver._onResponse.bind(this, driver, remote, options, deferred));
1990 req.end(body);
200
2010 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) {
2190 this.data = '';
2200 response.on('data', driver._concatDataChunks.bind(this));
2210 response.on('end', driver._onResponseEnd.bind(this, driver, response, remote, options, deferred));
2220 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) {
2350 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) {
2520 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) {
2690 if (remote.onError) {
2700 remote.onError.call(this, response, remote, options, deferred, this.data);
271 }
2720 return this;
273 },
274
275 /**
276 * On success callback function
277 *
278 * @method _onSuccess
279 * @param {DalekJs.Internal.Driver} driver Driver instance
280 * @param {object} response Response from the webdriver server
281 * @param {object} remote Dummy request body (function name, url, method)
282 * @param {object} options Request options (method, port, path, headers, etc.)
283 * @param {object} deferred Webdriver command deferred
284 * @chainable
285 * @private
286 */
287
288 _onSuccess: function (driver, response, remote, options, deferred) {
289 // log response data
2900 this.events.emit('driver:webdriver:response', {
291 statusCode: response.statusCode,
292 method: response.req.method,
293 path: response.req.path,
294 data: this.data
295 });
296
2970 if (remote.onResponse) {
2980 remote.onResponse.call(this, response, remote, options, deferred, this.data);
299 } else {
3000 deferred.resolve(this.data);
301 }
3020 return this;
303 }
304 };
305
3061 return Driver;
307};
308

/home/ubuntu/src/github.com/dalekjs/dalek-internal-webdriver/lib/webdriver.js

44%
9
4
5
LineHitsSource
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
251'use strict';
26
27/**
28 * Stores the injected options as an object property
29 *
30 * @param {object} opts Webdriver options
31 * @constructor
32 */
33
341var WebDriver = function (opts, events) {
350 this.events = events;
360 this.opts = opts;
37};
38
39/**
40 * Webdriver base class
41 *
42 * @namespace Internal
43 * @module DalekJS
44 * @class Webdriver
45 */
46
471WebDriver.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 () {
640 return !!this.options.sessionId;
65 },
66
67 /**
68 * Closes the current webdriver session
69 *
70 * @method hasSession
71 * @chainable
72 */
73
74 closeSession: function () {
750 delete this.options.sessionId;
760 return this;
77 }
78};
79
80// export the module
811module.exports = WebDriver;
82