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 Q = require('q'); |
29 | 1 | var fs = require('fs'); |
30 | 1 | var path = require('path'); |
31 | 1 | var rimraf = require('rimraf'); |
32 | 1 | var which = require('which').sync; |
33 | 1 | var portscanner = require('portscanner'); |
34 | 1 | var spawn = require('child_process').spawn; |
35 | 1 | var Events = require('events').EventEmitter; |
36 | ||
37 | // int. libs | |
38 | 1 | var Marionette = require('./lib/marionette'); |
39 | 1 | var WebDriverServer = require('./lib/webdriver'); |
40 | ||
41 | /** | |
42 | * This module is a browser plugin for [DalekJS](//github.com/dalekjs/dalek). | |
43 | * It provides all a WebDriverServer & browser launcher for Mozilla Firefox & Firefox OS. | |
44 | * | |
45 | * The browser plugin can be installed with the following command: | |
46 | * | |
47 | * ```bash | |
48 | * $ npm install dalek-browser-firefox --save-dev | |
49 | * ``` | |
50 | * | |
51 | * You can use the browser plugin by adding a config option to the your Dalekfile | |
52 | * | |
53 | * ```javascript | |
54 | * "browser": ["firefox"] | |
55 | * ``` | |
56 | * | |
57 | * Or you can tell Dalek that it should test in this browser via the command line: | |
58 | * | |
59 | * ```bash | |
60 | * $ dalek mytest.js -b firefox | |
61 | * ``` | |
62 | * | |
63 | * Dalek looks for the browser in the std. installation directory, if you installed the | |
64 | * browser in a different place, you can add the location of the browser executable to you Dalekfile, | |
65 | * because Dalek isnʼt capable of finding the executable yet on its own. | |
66 | * | |
67 | * ```javascript | |
68 | * "browsers": [{ | |
69 | * "firefox": { | |
70 | * "path": "~/Apps/FirefoxNightlyDebug.app/Contents/MacOS/firefox-bin" | |
71 | * } | |
72 | * }] | |
73 | * ``` | |
74 | * | |
75 | * The Firefox plugin only implements a subset of Dalekʼs assertions & actions, | |
76 | * so if you run into any bugs, the issue is most probably related to missing commands. | |
77 | * Please report any issues you find, Thank you :) | |
78 | * | |
79 | * The Webdriver Server tries to open Port 9006 by default, | |
80 | * if this port is blocked, it tries to use a port between 9007 & 9096 | |
81 | * You can specifiy a different port from within your [Dalekfile](/pages/config.html) like so: | |
82 | * | |
83 | * ```javascript | |
84 | * "browsers": [{ | |
85 | * "firefox": { | |
86 | * "port": 5555 | |
87 | * } | |
88 | * }] | |
89 | * ``` | |
90 | * | |
91 | * It is also possible to specify a range of ports: | |
92 | * | |
93 | * ```javascript | |
94 | * "browsers": [{ | |
95 | * "firefox": { | |
96 | * "portRange": [6100, 6120] | |
97 | * } | |
98 | * }] | |
99 | * ``` | |
100 | * | |
101 | * If you would like to test Nightly, Aurora oder Firefox OS releases, you can simply apply a snd. argument, | |
102 | * which defines the browser type: | |
103 | * | |
104 | * ```bash | |
105 | * $ dalek mytest.js -b firefox:aurora | |
106 | * ``` | |
107 | * | |
108 | * for Firefox Aurora, and if you would like to use the Firefox OS, just append `:os`: | |
109 | * | |
110 | * ```bash | |
111 | * $ dalek mytest.js -b firefox:os | |
112 | * ``` | |
113 | * | |
114 | * This will only work if you installed your browser in the default locations, | |
115 | * if the browsers binary is located in a non default location, you are able to specify | |
116 | * its location in your [Dalekfile](/pages/config.html): | |
117 | * | |
118 | * ```javascript | |
119 | * "browsers": [{ | |
120 | * "firefox": { | |
121 | * "binary": "/Applications/Custom Located Firefox.app/MacOS/Contents/firefox-bin" | |
122 | * } | |
123 | * }] | |
124 | * ``` | |
125 | * | |
126 | * This also works for the aurora & Firefox OS builds | |
127 | * | |
128 | * ```javascript | |
129 | * "browsers": [{ | |
130 | * "firefox:aurora": { | |
131 | * "binary": "/Applications/Custom Located Firefox Aurora.app/MacOS/Contents/firefox-bin" | |
132 | * } | |
133 | * }] | |
134 | * ``` | |
135 | * | |
136 | * @module DalekJS | |
137 | * @class FirefoxDriver | |
138 | * @namespace Browser | |
139 | * @part Firefox | |
140 | * @api | |
141 | */ | |
142 | ||
143 | 1 | var FirefoxDriver = { |
144 | ||
145 | /** | |
146 | * Verbose version of the browser name | |
147 | * | |
148 | * @property longName | |
149 | * @type string | |
150 | * @default Mozilla Firefox | |
151 | */ | |
152 | ||
153 | longName: 'Mozilla Firefox', | |
154 | ||
155 | /** | |
156 | * Default port of the FirefoxWebDriverServer | |
157 | * The port may change, cause the port conflict resolution | |
158 | * tool might pick another one, if the default one is blocked | |
159 | * | |
160 | * @property port | |
161 | * @type integer | |
162 | * @default 9006 | |
163 | */ | |
164 | ||
165 | port: 9006, | |
166 | ||
167 | /** | |
168 | * Default maximum port of the WebDriverServer | |
169 | * The port is the highest port in the range that can be allocated | |
170 | * by the WebDriverServer | |
171 | * | |
172 | * @property maxPort | |
173 | * @type integer | |
174 | * @default 9096 | |
175 | */ | |
176 | ||
177 | maxPort: 9096, | |
178 | ||
179 | /** | |
180 | * Default port of the Marionette TCP service | |
181 | * The port may change, cause the port conflict resolution | |
182 | * tool might pick another one, if the default one is blocked | |
183 | * | |
184 | * @property marionettePort | |
185 | * @type integer | |
186 | * @default 2828 | |
187 | */ | |
188 | ||
189 | marionettePort: 2828, | |
190 | ||
191 | /** | |
192 | * Default host of the FirefoxWebDriverServer | |
193 | * The host may be overridden with | |
194 | * a user configured value | |
195 | * | |
196 | * @property host | |
197 | * @type string | |
198 | * @default localhost | |
199 | */ | |
200 | ||
201 | host: 'localhost', | |
202 | ||
203 | /** | |
204 | * Default desired capabilities that should be | |
205 | * transferred when the browser session gets requested | |
206 | * | |
207 | * @property desiredCapabilities | |
208 | * @type object | |
209 | */ | |
210 | ||
211 | desiredCapabilities: { | |
212 | browserName: 'firefox' | |
213 | }, | |
214 | ||
215 | /** | |
216 | * Driver defaults, what should the driver be able to access. | |
217 | * | |
218 | * @property driverDefaults | |
219 | * @type object | |
220 | */ | |
221 | ||
222 | driverDefaults: { | |
223 | viewport: true, | |
224 | status: true, | |
225 | sessionInfo: true | |
226 | }, | |
227 | ||
228 | /** | |
229 | * Root path of the FirefoxWebDriverServer | |
230 | * | |
231 | * @property path | |
232 | * @type string | |
233 | * @default '' | |
234 | */ | |
235 | ||
236 | path: '', | |
237 | ||
238 | /** | |
239 | * Path to the Firefox binary file | |
240 | * | |
241 | * @property binary | |
242 | * @type string | |
243 | * @default null | |
244 | */ | |
245 | ||
246 | binary: null, | |
247 | ||
248 | /** | |
249 | * Paths to the default Firefox binary files | |
250 | * | |
251 | * @property defaultBinaries | |
252 | * @type object | |
253 | */ | |
254 | ||
255 | defaultBinaries: { | |
256 | default: 'firefox', | |
257 | darwin: '/Applications/Firefox.app/Contents/MacOS/firefox-bin', | |
258 | win32: process.env.ProgramFiles + '\\Mozilla Firefox\\firefox.exe', | |
259 | win64: process.env['ProgramFiles(x86)'] + '\\Mozilla Firefox\\firefox.exe' | |
260 | }, | |
261 | ||
262 | /** | |
263 | * Different browser types (Aurora / firefox OS) that can be controlled | |
264 | * via the Firefox driver | |
265 | * | |
266 | * @property browserTypes | |
267 | * @type object | |
268 | */ | |
269 | ||
270 | browserTypes: { | |
271 | ||
272 | /** | |
273 | * Nightly Firefox | |
274 | * | |
275 | * @property nightly | |
276 | * @type object | |
277 | */ | |
278 | ||
279 | nightly: { | |
280 | name: 'Firefox Nightly', | |
281 | linux: 'firefox', | |
282 | darwin: '/Applications/FirefoxNightlyDebug.app/Contents/MacOS/firefox-bin', | |
283 | win32: process.env.ProgramFiles + '\\Nightly\\firefox.exe', | |
284 | win64: process.env['ProgramFiles(x86)'] + '\\Mozilla Firefox Nightly\\firefox.exe' | |
285 | }, | |
286 | ||
287 | /** | |
288 | * Firefox Aurora | |
289 | * | |
290 | * @property aurora | |
291 | * @type object | |
292 | */ | |
293 | ||
294 | aurora: { | |
295 | name: 'Firefox Aurora', | |
296 | linux: 'firefox', | |
297 | darwin: '/Applications/FirefoxAuroraDebug.app/Contents/MacOS/firefox-bin', | |
298 | win32: process.env.ProgramFiles + '\\AuroraDebug\\firefox.exe', | |
299 | win64: process.env['ProgramFiles(x86)'] + '\\Mozilla AuroraDebug\\firefox.exe' | |
300 | }, | |
301 | ||
302 | /** | |
303 | * Firefox OS | |
304 | * | |
305 | * @property os | |
306 | * @type object | |
307 | */ | |
308 | ||
309 | os: { | |
310 | name: 'Firefox OS', | |
311 | linux: 'b2g', | |
312 | darwin: '/Applications/B2G.app/Contents/MacOS/b2g', | |
313 | win32: process.env.ProgramFiles + '\\B2G\\b2g.exe', | |
314 | win64: process.env.ProgramFiles + '\\B2G\\b2g.exe' | |
315 | } | |
316 | }, | |
317 | ||
318 | /** | |
319 | * Child process instance of the Firefox browser | |
320 | * | |
321 | * @property spawned | |
322 | * @type null|Object | |
323 | * @default null | |
324 | */ | |
325 | ||
326 | spawned: null, | |
327 | ||
328 | /** | |
329 | * Collected data about the created profile, | |
330 | * path, name, etc. | |
331 | * | |
332 | * @property profile | |
333 | * @type null|object | |
334 | * @default null | |
335 | */ | |
336 | ||
337 | profile: null, | |
338 | ||
339 | /** | |
340 | * Resolves the driver port | |
341 | * | |
342 | * @method getPort | |
343 | * @return {integer} port WebDriver server port | |
344 | */ | |
345 | ||
346 | getPort: function () { | |
347 | 1 | return this.port; |
348 | }, | |
349 | ||
350 | /** | |
351 | * Resolves the maximum range for the driver port | |
352 | * | |
353 | * @method getMaxPort | |
354 | * @return {integer} port Max WebDriver server port range | |
355 | */ | |
356 | ||
357 | getMaxPort: function () { | |
358 | 0 | return this.maxPort; |
359 | }, | |
360 | ||
361 | /** | |
362 | * Resolves the marionette port | |
363 | * | |
364 | * @method getMarionettePort | |
365 | * @return {integer} port Marionette server port | |
366 | */ | |
367 | ||
368 | getMarionettePort: function () { | |
369 | 1 | return this.marionettePort; |
370 | }, | |
371 | ||
372 | /** | |
373 | * Returns the driver host | |
374 | * | |
375 | * @method getHost | |
376 | * @return {string} host WebDriver server hostname | |
377 | */ | |
378 | ||
379 | getHost: function () { | |
380 | 1 | return this.host; |
381 | }, | |
382 | ||
383 | /** | |
384 | * Launches the FirefoxWebDriverServer, | |
385 | * the marionette client, & the browser. | |
386 | * Creates a user profile for the browser | |
387 | * | |
388 | * @method launch | |
389 | * @param {object} configuration Browser configuration | |
390 | * @param {EventEmitter2} events EventEmitter (Reporter Emitter instance) | |
391 | * @param {Dalek.Internal.Config} config Dalek configuration class | |
392 | * @return {object} promise Browser promise | |
393 | */ | |
394 | ||
395 | launch: function (configuration, events, config) { | |
396 | 0 | var deferred = Q.defer(); |
397 | ||
398 | // init the webdriver server, | |
399 | // marionette client, event glue | |
400 | // and configuration settings | |
401 | 0 | configuration = this._initialize({ |
402 | userconfig: configuration, | |
403 | reporterEvents: events, | |
404 | config: config, | |
405 | events: new Events() | |
406 | }); | |
407 | ||
408 | // check for a user set port | |
409 | 0 | var browsers = this.config.get('browsers'); |
410 | 0 | if (browsers && Array.isArray(browsers)) { |
411 | 0 | browsers.forEach(this._checkUserDefinedPorts.bind(this)); |
412 | } | |
413 | ||
414 | // check the path of the browser binary | |
415 | 0 | Q.when(this.findBrowserBinary(configuration)) |
416 | .then(this._afterBinaryFound.bind(this, configuration, deferred)); | |
417 | ||
418 | 0 | return deferred.promise; |
419 | }, | |
420 | ||
421 | /** | |
422 | * Shuts down the TCP (Marionette) & HTTP connection (Webdriver), | |
423 | * then kills the browser process & cleans up the profiles | |
424 | * | |
425 | * @method kill | |
426 | * @chainable | |
427 | */ | |
428 | ||
429 | kill: function () { | |
430 | 0 | Q.all([ |
431 | // shutdown Marionette client | |
432 | this.marionette.kill(), | |
433 | // shutdown webdriver server | |
434 | this.webDriverServer.kill() | |
435 | ]).then(this._killProcess.bind(this)); | |
436 | ||
437 | 0 | return this; |
438 | }, | |
439 | ||
440 | /** | |
441 | * Locates the browser binary | |
442 | * | |
443 | * @method findBrowserBinary | |
444 | * @param {object} options Config options | |
445 | * @return {object} Promise | |
446 | */ | |
447 | ||
448 | findBrowserBinary: function (options) { | |
449 | 0 | var deferred = Q.defer(); |
450 | ||
451 | // check if the user has set a custom binary | |
452 | 0 | if (options && options.binary) { |
453 | 0 | this._checkUserSetBinary(options.binary, deferred); |
454 | 0 | return deferred.promise; |
455 | } | |
456 | ||
457 | // get the defaukt binary for this OS | |
458 | 0 | var defaultBinary = this._getDefaultBinary(); |
459 | ||
460 | // check if the binary exists | |
461 | 0 | if (fs.existsSync(defaultBinary)) { |
462 | 0 | this.binary = defaultBinary; |
463 | 0 | deferred.resolve(defaultBinary); |
464 | } else { | |
465 | 0 | var msg = 'dalek-driver-firefox: Binary not found: ' + defaultBinary; |
466 | 0 | this.reporterEvents.emit('error', msg); |
467 | 0 | deferred.reject({error: true, msg: msg}); |
468 | } | |
469 | ||
470 | 0 | return deferred.promise; |
471 | }, | |
472 | ||
473 | /** | |
474 | * Makes all needed modifications after we are sure if the | |
475 | * browser binary has been found | |
476 | * | |
477 | * @method _afterBinaryFound | |
478 | * @param {object} configuration User configuration | |
479 | * @param {object} deferred Promise | |
480 | * @chainable | |
481 | * @private | |
482 | */ | |
483 | ||
484 | _afterBinaryFound: function (configuration, deferred) { | |
485 | // generate the verbose browser name | |
486 | 0 | this.longName = this._modifyVerboseBrowserName(configuration); |
487 | ||
488 | // check if we are driving a desktop browser | |
489 | // when, create a profile, else, not | |
490 | 0 | if (configuration.type !== 'os') { |
491 | 0 | Q.when(this._createProfile()) |
492 | .then(this._afterDesktopBinaryFound.bind(this, deferred, configuration)); | |
493 | } else { | |
494 | 0 | this._startBrowser(null, 'os', deferred); |
495 | } | |
496 | ||
497 | 0 | return this; |
498 | }, | |
499 | ||
500 | /** | |
501 | * Modifies the verbose browser name | |
502 | * | |
503 | * @method _modifyVerboseBrowserName | |
504 | * @param {object} configuration User configuration | |
505 | * @return {string} Verbose browser name | |
506 | * @private | |
507 | */ | |
508 | ||
509 | _modifyVerboseBrowserName: function (configuration) { | |
510 | 0 | if (configuration.type && this.browserTypes[configuration.type]) { |
511 | 0 | return this.browserTypes[configuration.type].name + ' (' + this.longName + ')'; |
512 | } else { | |
513 | 0 | return this.longName; |
514 | } | |
515 | }, | |
516 | ||
517 | /** | |
518 | * Initiates the browser startup after the desktop binary has been found | |
519 | * | |
520 | * @method _afterDesktopBinaryFound | |
521 | * @param {object} deferred Promise | |
522 | * @param {object} profile Profile data | |
523 | * @chainable | |
524 | * @private | |
525 | */ | |
526 | ||
527 | _afterDesktopBinaryFound: function (deferred, configuration) { | |
528 | 0 | this._startBrowser(this.profile.path, this.profile.name, deferred, configuration); |
529 | 0 | return this; |
530 | }, | |
531 | ||
532 | /** | |
533 | * Kills the currently running browser process | |
534 | * | |
535 | * @method _killProcess | |
536 | * @chainable | |
537 | * @priavte | |
538 | */ | |
539 | ||
540 | _killProcess: function () { | |
541 | // kill the browser process itself | |
542 | 0 | this.spawned.kill('SIGTERM'); |
543 | ||
544 | // check if we need to clean up some created profiles | |
545 | // should always be the case except for Firefox OS | |
546 | 0 | if (this.profile && this.profile.path) { |
547 | 0 | rimraf.sync(this.profile.path); |
548 | } | |
549 | ||
550 | 0 | return this; |
551 | }, | |
552 | ||
553 | /** | |
554 | * Initializes config & properties | |
555 | * | |
556 | * @method _initiaize | |
557 | * @param {object} opts Config options | |
558 | * @return {object} Processed userr config | |
559 | * @private | |
560 | */ | |
561 | ||
562 | _initialize: function (opts) { | |
563 | // store config class | |
564 | 0 | this.config = opts.config; |
565 | ||
566 | // glue events | |
567 | 0 | this.events = opts.events; |
568 | 0 | this.events.setMaxListeners(0); |
569 | 0 | this.reporterEvents = opts.reporterEvents; |
570 | ||
571 | // setup Marionette client & Webdriver server | |
572 | 0 | this.marionette = new Marionette(this.events); |
573 | 0 | this.webDriverServer = new WebDriverServer(this.events); |
574 | ||
575 | 0 | return opts.userconfig === null ? {} : opts.userconfig; |
576 | }, | |
577 | ||
578 | /** | |
579 | * Get the default binary location | |
580 | * | |
581 | * @method _getDefaultBinary | |
582 | * @return {string} Path to binary | |
583 | * @private | |
584 | */ | |
585 | ||
586 | _getDefaultBinary: function () { | |
587 | 0 | var platform = process.platform; |
588 | ||
589 | // check default binary for linuy | |
590 | 0 | if (platform !== 'darwin' && platform !== 'win32' && this.defaultBinaries[platform]) { |
591 | 0 | return which(this.defaultBinaries.linux); |
592 | } | |
593 | ||
594 | // check to see if we are on Windows x64 | |
595 | 0 | if (platform === 'win32' && process.arch === 'x64') { |
596 | 0 | platform = 'win64'; |
597 | } | |
598 | ||
599 | 0 | return this.defaultBinaries[platform] ? |
600 | this.defaultBinaries[platform] : | |
601 | which(this.defaultBinaries.default); | |
602 | }, | |
603 | ||
604 | /** | |
605 | * Launches the browser | |
606 | * | |
607 | * @method _startBrowser | |
608 | * @param {string} profilePath Directory that contains the profile | |
609 | * @param {string} profileName Name of the profile to use | |
610 | * @param {object} deferred Promise | |
611 | * @private | |
612 | * @chainable | |
613 | */ | |
614 | ||
615 | _startBrowser: function (profilePath, profileName, deferred, configuration) { | |
616 | 0 | var df = Q.defer(); |
617 | 0 | var args = []; |
618 | ||
619 | // set args based on environment | |
620 | 0 | if (profileName !== 'os') { |
621 | 0 | args = ['-marionette', '-turbo', '-profile', profilePath, '-no-remote', '-url', 'about:blank']; |
622 | } | |
623 | ||
624 | // start the browser | |
625 | 0 | this.spawned = spawn(this.binary, args); |
626 | ||
627 | // kind of an ugly hack, but I have no other idea to | |
628 | // than to wait for 2 secs to ensure Firefox runs on windows | |
629 | 0 | if (process.platform === 'win32' || (configuration && !configuration.type)) { |
630 | 0 | this.interval = setInterval(this._scanMarionettePort.bind(this, df), 50); |
631 | } else { | |
632 | 0 | this.spawned.stdout.on('data', this._onBrowserStartup.bind(this, df)); |
633 | } | |
634 | ||
635 | // connect to the marionette socket server | |
636 | // and the webdriver server & resolve the promise when done | |
637 | 0 | df.promise.then(this._resolvePort.bind(this, deferred, profileName)); |
638 | 0 | return this; |
639 | }, | |
640 | ||
641 | /** | |
642 | * Repeatadly checks the status of the marionette port | |
643 | * | |
644 | * @method _scanMarionettePort | |
645 | * @param {object} df Promise | |
646 | * @private | |
647 | * @chainable | |
648 | */ | |
649 | ||
650 | _scanMarionettePort: function (df) { | |
651 | 0 | portscanner.checkPortStatus(this.getMarionettePort(), this.getHost(), this._startByInterval.bind(this, df)); |
652 | 0 | return this; |
653 | }, | |
654 | ||
655 | /** | |
656 | * Checks if the browser is available by listening on the marionette socket | |
657 | * | |
658 | * @method _startByInterval | |
659 | * @param {object} df Promise | |
660 | * @param {object} interval Reference to the portchecker interval | |
661 | * @param {object|null} err Error or null | |
662 | * @param {string} status Status of the marionette port | |
663 | * @private | |
664 | * @chainable | |
665 | */ | |
666 | ||
667 | _startByInterval: function (df, err, status) { | |
668 | 0 | if (status === 'open') { |
669 | 0 | clearInterval(this.interval); |
670 | 0 | df.resolve(); |
671 | } | |
672 | ||
673 | 0 | return this; |
674 | }, | |
675 | ||
676 | /** | |
677 | * Process user defined ports | |
678 | * | |
679 | * @method _checkUserDefinedPorts | |
680 | * @param {object} browser Browser configuration | |
681 | * @chainable | |
682 | * @private | |
683 | */ | |
684 | ||
685 | _checkUserDefinedPorts: function (browser) { | |
686 | // check for a single defined port | |
687 | 0 | if (browser.firefox && browser.firefox.port) { |
688 | 0 | this.port = parseInt(browser.firefox.port, 10); |
689 | 0 | this.maxPort = this.port + 90; |
690 | 0 | this.reporterEvents.emit('report:log:system', 'dalek-browser-firefox: Switching to user defined port: ' + this.port); |
691 | } | |
692 | ||
693 | // check for a port range | |
694 | 0 | if (browser.firefox && browser.firefox.portRange && browser.firefox.portRange.length === 2) { |
695 | 0 | this.port = parseInt(browser.firefox.portRange[0], 10); |
696 | 0 | this.maxPort = parseInt(browser.firefox.portRange[1], 10); |
697 | 0 | this.reporterEvents.emit('report:log:system', 'dalek-browser-firefox: Switching to user defined port(s): ' + this.port + ' -> ' + this.maxPort); |
698 | } | |
699 | ||
700 | 0 | return this; |
701 | }, | |
702 | ||
703 | /** | |
704 | * Resolve the WebDriverServer port | |
705 | * | |
706 | * @method _resolvePort | |
707 | * @param {object} deferred Promise | |
708 | * @param {string} profileName Name of the profile | |
709 | * @chainable | |
710 | * @private | |
711 | */ | |
712 | ||
713 | _resolvePort: function (deferred, profileName) { | |
714 | // check if the current port is in use, if so, scan for free ports | |
715 | 0 | portscanner.findAPortNotInUse( |
716 | this.getPort(), | |
717 | this.getMaxPort(), | |
718 | this.getHost(), | |
719 | this._afterPortResolved.bind(this, deferred, profileName) | |
720 | ); | |
721 | ||
722 | 0 | return this; |
723 | }, | |
724 | ||
725 | /** | |
726 | * Resolve the WebDriverServer port | |
727 | * | |
728 | * @method _resolvePort | |
729 | * @param {object} deferred Promise | |
730 | * @param {string} profileName Name of the profile | |
731 | * @param {object|null} error Error object if there is one | |
732 | * @param {integer} port Resolved port | |
733 | * @chainable | |
734 | * @private | |
735 | */ | |
736 | ||
737 | _afterPortResolved: function (deferred, profileName, error, port) { | |
738 | // check for errors | |
739 | 0 | if (error !== null && error.code !== 'ECONNREFUSED') { |
740 | 0 | this.reporterEvents.emit('error', 'dalek-browser-firefox: Error starting WebDriverServer, port ' + port + ' in use'); |
741 | 0 | deferred.reject(error); |
742 | 0 | process.exit(); |
743 | } | |
744 | ||
745 | // check if the port was blocked & if we need to switch to another port | |
746 | 0 | if (this.port !== port) { |
747 | 0 | this.reporterEvents.emit('report:log:system', 'dalek-browser-firefox: Switching to port: ' + port); |
748 | 0 | this.port = port; |
749 | } | |
750 | ||
751 | // kickstart marionette client & webdriver server | |
752 | 0 | Q.all([ |
753 | this.webDriverServer.connect(this.getPort(), this.getHost()), | |
754 | this.marionette.connect(this.getMarionettePort()) | |
755 | ]).then(this._afterConnectionHasBeenEstablished.bind(this, profileName, deferred)); | |
756 | 0 | return this; |
757 | }, | |
758 | ||
759 | /** | |
760 | * Callback that will be invoked after the marionette client has | |
761 | * established a connection to the browser & after the webdriver server | |
762 | * has been launched correctly | |
763 | * | |
764 | * @method _afterConnectionHasBeenEstablished | |
765 | * @param {string} profileName Name of the user profile | |
766 | * @param {object} deferred Promise | |
767 | * @chainable | |
768 | * @private | |
769 | */ | |
770 | ||
771 | _afterConnectionHasBeenEstablished: function (profileName, deferred) { | |
772 | // Due to the lack of firefox os readiness events, | |
773 | // we need to wait an additional second before reporting | |
774 | // test readiness | |
775 | 0 | if (profileName === 'os') { |
776 | 0 | setTimeout(deferred.resolve, 1000); |
777 | } else { | |
778 | 0 | deferred.resolve(); |
779 | } | |
780 | ||
781 | 0 | return this; |
782 | }, | |
783 | ||
784 | /** | |
785 | * Consumes the console output when the browser is started | |
786 | * | |
787 | * @method _onBrowserStartup | |
788 | * @param {object} deferred Promise | |
789 | * @param {string} data Output from the spawned binary | |
790 | * @private | |
791 | * @chainable | |
792 | */ | |
793 | ||
794 | _onBrowserStartup: function (deferred, data) { | |
795 | 0 | if (this._browserIsReady(data)) { |
796 | 0 | deferred.resolve(); |
797 | } | |
798 | 0 | return this; |
799 | }, | |
800 | ||
801 | /** | |
802 | * Checks if the browser is ready for communication | |
803 | * | |
804 | * @method _browserIsReady | |
805 | * @param {string} data Output from the spawned binary | |
806 | * @return {bool} true when ready, false when not | |
807 | * @private | |
808 | */ | |
809 | ||
810 | _browserIsReady: function (data) { | |
811 | // convert buffer to string | |
812 | 0 | data = data+''; |
813 | // check for the ready signal on desktop firefox | |
814 | 0 | var desktopReady = data.search('DOMWINDOW == 12') !== -1; |
815 | // check for the ready signal of the firefoxos emulator | |
816 | 0 | var b2gReady = data.search('BrowserElementChildPreload.js loaded') !== -1; |
817 | 0 | return desktopReady || b2gReady; |
818 | ||
819 | }, | |
820 | ||
821 | /** | |
822 | * Creates a new Firefox profile | |
823 | * | |
824 | * @method _createProfile | |
825 | * @return {Q.promise} | |
826 | * @private | |
827 | */ | |
828 | ||
829 | _createProfile: function () { | |
830 | 0 | var deferred = Q.defer(); |
831 | 0 | var profileName = 'dalekjs-' + Math.random().toString(16).slice(2); |
832 | 0 | this._createUserPreferences(deferred, profileName); |
833 | ||
834 | 0 | return deferred.promise; |
835 | }, | |
836 | ||
837 | /** | |
838 | * Creates user preferences for the profile | |
839 | * Saves them in `user.js` in the newly created profile | |
840 | * | |
841 | * @method _createProfile | |
842 | * @param {string} profilePath User profile directory | |
843 | * @return {Q.promise} | |
844 | * @private | |
845 | */ | |
846 | ||
847 | _createUserPreferences: function (deferred, profileName) { | |
848 | // create marionette specific user preferences | |
849 | 0 | var prefs = 'user_pref("browser.shell.checkDefaultBrowser", false);\n'; |
850 | 0 | prefs += 'user_pref("marionette.contentListener", false);\n'; |
851 | 0 | prefs += 'user_pref("marionette.defaultPrefs.enabled", true);\n'; |
852 | 0 | prefs += 'user_pref("browser.shell.checkDefaultBrowser", false);\n'; |
853 | 0 | prefs += 'user_pref("browser.sessionstore.resume_from_crash", false);\n'; |
854 | 0 | prefs += 'user_pref("browser.bookmarks.restore_default_bookmarks", false);\n'; |
855 | 0 | prefs += 'user_pref("marionette.defaultPrefs.port", "' + this.getMarionettePort() + '");\n'; |
856 | ||
857 | // store the user preferences | |
858 | 0 | this.profile = {}; |
859 | 0 | this.profile.path = path.join(process.cwd(), 'temp'); |
860 | 0 | this.profile.name = profileName; |
861 | ||
862 | // check if the temp dir exists, else create | |
863 | 0 | if (!fs.existsSync(this.profile.path)) { |
864 | 0 | fs.mkdirSync(this.profile.path); |
865 | } | |
866 | ||
867 | // create the preference file | |
868 | 0 | fs.writeFile(path.join(this.profile.path, 'prefs.js'), prefs, this._afterCreatingUserPreferences.bind(this, deferred)); |
869 | 0 | return deferred.promise; |
870 | }, | |
871 | ||
872 | /** | |
873 | * Callback that will be executed after the user preferences | |
874 | * have been created | |
875 | * | |
876 | * @method _afterCreatingUserPreferences | |
877 | * @param {object} deferred Promise | |
878 | * @param {object|null} err Error or null | |
879 | * @private | |
880 | * @chainable | |
881 | */ | |
882 | ||
883 | _afterCreatingUserPreferences: function (deferred, err) { | |
884 | // reject the deferred when an error occurrs | |
885 | 0 | if (err !== null) { |
886 | 0 | this.reporterEvents.emit('error', 'dalek-browser-firefox: Error creating profile'); |
887 | 0 | deferred.reject(err); |
888 | 0 | process.exit(); |
889 | } | |
890 | ||
891 | 0 | deferred.resolve(); |
892 | 0 | return this; |
893 | }, | |
894 | ||
895 | /** | |
896 | * Checks if the binary exists, | |
897 | * when set manually by the user | |
898 | * | |
899 | * @method _checkUserSetBinary | |
900 | * @param {string} userPath Path to the browser binary | |
901 | * @param {object} deferred Promise | |
902 | * @private | |
903 | * @chainable | |
904 | */ | |
905 | ||
906 | _checkUserSetBinary: function (userPath, deferred) { | |
907 | // check if we need to replace the users home directory | |
908 | 0 | if (process.platform === 'darwin' && userPath.trim()[0] === '~') { |
909 | 0 | userPath = userPath.replace('~', process.env.HOME); |
910 | } | |
911 | ||
912 | // check if the binary exists | |
913 | 0 | if (fs.existsSync(userPath)) { |
914 | 0 | this.binary = userPath; |
915 | 0 | deferred.resolve(userPath); |
916 | } else { | |
917 | 0 | var msg = 'dalek-driver-firefox: Binary not found: ' + userPath; |
918 | 0 | this.reporterEvents.emit('error', msg); |
919 | 0 | process.exit(); // MAYBE switch to Daleks 'killAll' Event |
920 | 0 | deferred.reject({error: true, msg: msg}); |
921 | } | |
922 | ||
923 | 0 | return this; |
924 | } | |
925 | }; | |
926 | ||
927 | 1 | module.exports = FirefoxDriver; |
928 |
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 | * Cookie related Marionette commands | |
29 | * see [JsonProtocol](https://wiki.mozilla.org/Auto-tools/Projects/Marionette/JSON_Protocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class Cookie | |
33 | * @namespace FirefoxDriver.Commands.Marionette | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function (Marionette) { |
37 | ||
38 | /** | |
39 | * Retrieve all cookies visible to the current page. | |
40 | * | |
41 | * @method getCookies | |
42 | */ | |
43 | ||
44 | 0 | Marionette.addCommand({ |
45 | name: 'getCookies', | |
46 | request: { | |
47 | to: ':marionetteId', | |
48 | session: ':sessionId', | |
49 | name: 'getAllCookies' | |
50 | } | |
51 | }); | |
52 | ||
53 | /** | |
54 | * Delete all cookies visible to the current page. | |
55 | * | |
56 | * @method deleteCookies | |
57 | */ | |
58 | ||
59 | 0 | Marionette.addCommand({ |
60 | name: 'deleteCookies', | |
61 | request: { | |
62 | to: ':marionetteId', | |
63 | session: ':sessionId', | |
64 | name: 'deleteAllCookies' | |
65 | } | |
66 | }); | |
67 | ||
68 | /** | |
69 | * Delete the cookie with the given name. | |
70 | * This command should be a no-op if there is no such cookie visible to the current page. | |
71 | * | |
72 | * @method deleteCookie | |
73 | */ | |
74 | ||
75 | 0 | Marionette.addCommand({ |
76 | name: 'deleteCookie', | |
77 | request: { | |
78 | to: ':marionetteId', | |
79 | session: ':sessionId', | |
80 | name: 'deleteCookie', | |
81 | parameters: { | |
82 | name: ':name', | |
83 | } | |
84 | } | |
85 | }); | |
86 | ||
87 | /** | |
88 | * Set a cookie. If the cookie path is not specified, it should be set to "/". | |
89 | * Likewise, if the domain is omitted, it should default to the current page's domain. | |
90 | * | |
91 | * @method addCookie | |
92 | */ | |
93 | ||
94 | 0 | Marionette.addCommand({ |
95 | name: 'cookies', | |
96 | request: { | |
97 | to: ':marionetteId', | |
98 | session: ':sessionId', | |
99 | cookie: ':cookie', | |
100 | name: 'addCookie' | |
101 | } | |
102 | }); | |
103 | ||
104 | }; | |
105 |
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 | * Element related Marionette commands | |
29 | * see [JsonProtocol](https://wiki.mozilla.org/Auto-tools/Projects/Marionette/JSON_Protocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class Element | |
33 | * @namespace FirefoxDriver.Commands.Marionette | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function (Marionette) { |
37 | ||
38 | /** | |
39 | * Selects an element | |
40 | * | |
41 | * @method element | |
42 | */ | |
43 | ||
44 | 0 | Marionette.addCommand({ |
45 | name: 'element', | |
46 | params: ['selector'], | |
47 | request: { | |
48 | to: ':marionetteId', | |
49 | session: ':sessionId', | |
50 | name: 'findElement', | |
51 | parameters: { | |
52 | value: ':selector', | |
53 | using: 'css selector' | |
54 | } | |
55 | } | |
56 | }); | |
57 | ||
58 | /** | |
59 | * Selects multiple elements | |
60 | * | |
61 | * @method elements | |
62 | */ | |
63 | ||
64 | 0 | Marionette.addCommand({ |
65 | name: 'elements', | |
66 | params: ['selector'], | |
67 | request: { | |
68 | to: ':marionetteId', | |
69 | session: ':sessionId', | |
70 | name: 'findElements', | |
71 | parameters: { | |
72 | value: ':selector', | |
73 | using: 'css selector' | |
74 | } | |
75 | } | |
76 | }); | |
77 | ||
78 | /** | |
79 | * Clicks an element | |
80 | * | |
81 | * @method click | |
82 | */ | |
83 | ||
84 | 0 | Marionette.addCommand({ |
85 | name: 'click', | |
86 | params: ['elementId'], | |
87 | request: { | |
88 | to: ':marionetteId', | |
89 | session: ':sessionId', | |
90 | element: ':elementId', | |
91 | name: 'clickElement' | |
92 | } | |
93 | }); | |
94 | ||
95 | /** | |
96 | * Gets the width & height of an element | |
97 | * | |
98 | * @method size | |
99 | */ | |
100 | ||
101 | 0 | Marionette.addCommand({ |
102 | name: 'size', | |
103 | params: ['elementId'], | |
104 | request: { | |
105 | to: ':marionetteId', | |
106 | session: ':sessionId', | |
107 | element: ':elementId', | |
108 | name: 'getElementSize' | |
109 | } | |
110 | }); | |
111 | ||
112 | /** | |
113 | * Checks if an element is displayed | |
114 | * | |
115 | * @method displayed | |
116 | */ | |
117 | ||
118 | 0 | Marionette.addCommand({ |
119 | name: 'displayed', | |
120 | params: ['elementId'], | |
121 | request: { | |
122 | to: ':marionetteId', | |
123 | session: ':sessionId', | |
124 | element: ':elementId', | |
125 | name: 'isElementDisplayed' | |
126 | } | |
127 | }); | |
128 | ||
129 | /** | |
130 | * Gets the inner text of an element | |
131 | * | |
132 | * @method text | |
133 | */ | |
134 | ||
135 | 0 | Marionette.addCommand({ |
136 | name: 'text', | |
137 | params: ['elementId'], | |
138 | request: { | |
139 | to: ':marionetteId', | |
140 | session: ':sessionId', | |
141 | name: 'getElementText', | |
142 | parameters: { | |
143 | id: ':elementId' | |
144 | } | |
145 | } | |
146 | }); | |
147 | ||
148 | /** | |
149 | * Gets the value of an element | |
150 | * | |
151 | * @method val | |
152 | */ | |
153 | ||
154 | 0 | Marionette.addCommand({ |
155 | name: 'val', | |
156 | params: ['elementId', 'value'], | |
157 | request: { | |
158 | to: ':marionetteId', | |
159 | session: ':sessionId', | |
160 | parameters: { | |
161 | id: ':elementId', | |
162 | value: ':value' | |
163 | }, | |
164 | name: 'sendKeysToElement' | |
165 | } | |
166 | }); | |
167 | ||
168 | /** | |
169 | * Clears the contents of an input/text field | |
170 | * | |
171 | * @method clear | |
172 | */ | |
173 | ||
174 | 0 | Marionette.addCommand({ |
175 | name: 'clear', | |
176 | params: ['elementId'], | |
177 | request: { | |
178 | to: ':marionetteId', | |
179 | session: ':sessionId', | |
180 | parameters: { | |
181 | id: ':elementId' | |
182 | }, | |
183 | name: 'clearElement' | |
184 | } | |
185 | }); | |
186 | ||
187 | /** | |
188 | * Gets the value of an css property | |
189 | * | |
190 | * @method cssProperty | |
191 | */ | |
192 | ||
193 | 0 | Marionette.addCommand({ |
194 | name: 'cssProperty', | |
195 | params: ['elementId'], | |
196 | request: { | |
197 | to: ':marionetteId', | |
198 | session: ':sessionId', | |
199 | parameters: { | |
200 | id: ':elementId', | |
201 | propertyName: ':propertyName' | |
202 | }, | |
203 | name: 'getElementValueOfCssProperty' | |
204 | } | |
205 | }); | |
206 | ||
207 | /** | |
208 | * Checks if an element is enabled | |
209 | * | |
210 | * @method enabled | |
211 | */ | |
212 | ||
213 | 0 | Marionette.addCommand({ |
214 | name: 'enabled', | |
215 | params: ['elementId'], | |
216 | request: { | |
217 | to: ':marionetteId', | |
218 | session: ':sessionId', | |
219 | parameters: { | |
220 | id: ':elementId' | |
221 | }, | |
222 | name: 'isElementEnabled' | |
223 | } | |
224 | }); | |
225 | ||
226 | /** | |
227 | * Checks if an element is selected | |
228 | * | |
229 | * @method selected | |
230 | */ | |
231 | ||
232 | 0 | Marionette.addCommand({ |
233 | name: 'selected', | |
234 | params: ['elementId'], | |
235 | request: { | |
236 | to: ':marionetteId', | |
237 | session: ':sessionId', | |
238 | parameters: { | |
239 | id: ':elementId' | |
240 | }, | |
241 | name: 'isElementSelected' | |
242 | } | |
243 | }); | |
244 | ||
245 | /** | |
246 | * TODO: Find JS workaround (Marionette doesn't has a submit handler yet) | |
247 | * DOES NOT WORK YET! | |
248 | * | |
249 | * @method submit | |
250 | */ | |
251 | ||
252 | 0 | Marionette.addCommand({ |
253 | name: 'submit', | |
254 | params: ['elementId'], | |
255 | request: { | |
256 | to: ':marionetteId', | |
257 | session: ':sessionId', | |
258 | name: 'executeScript', | |
259 | value: 'document.form[0].submit()', | |
260 | newSandbox: true, | |
261 | specialPowers: true | |
262 | } | |
263 | }); | |
264 | ||
265 | /** | |
266 | * Gets the value of an specific attribute | |
267 | * | |
268 | * @method attribute | |
269 | */ | |
270 | ||
271 | 0 | Marionette.addCommand({ |
272 | name: 'attribute', | |
273 | params: ['elementId', 'attr'], | |
274 | request: { | |
275 | to: ':marionetteId', | |
276 | session: ':sessionId', | |
277 | parameters: { | |
278 | id: ':elementId', | |
279 | name: ':attr' | |
280 | }, | |
281 | name: 'getElementAttribute' | |
282 | } | |
283 | }); | |
284 | ||
285 | }; | |
286 |
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 | * Script execute related Marionette commands | |
29 | * see [JsonProtocol](https://wiki.mozilla.org/Auto-tools/Projects/Marionette/JSON_Protocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class Execute | |
33 | * @namespace FirefoxDriver.Commands.Marionette | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function (Marionette) { |
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 | */ | |
48 | ||
49 | 0 | Marionette.addCommand({ |
50 | name: 'execute', | |
51 | request: { | |
52 | to: ':marionetteId', | |
53 | session: ':sessionId', | |
54 | name: 'executeScript', | |
55 | parameters: { | |
56 | script: ':value', | |
57 | args: ':args', | |
58 | newSandbox: true, | |
59 | specialPowers: true | |
60 | } | |
61 | } | |
62 | }); | |
63 | ||
64 | /** | |
65 | * Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. | |
66 | * The executed script is assumed to be asynchronous and must signal that is done by invoking the provided callback, | |
67 | * which is always provided as the final argument to the function. The value to this callback will be returned to the client. | |
68 | * Asynchronous script commands may not span page loads. | |
69 | * If an unload event is fired while waiting for a script result, an error should be returned to the client. | |
70 | * | |
71 | * The script argument defines the script to execute in teh form of a function body. | |
72 | * The function will be invoked with the provided args array and the values may be accessed | |
73 | * via the arguments object in the order specified. | |
74 | * The final argument will always be a callback function that must be invoked to signal that the script has finished. | |
75 | * | |
76 | * @method executeAsync | |
77 | */ | |
78 | ||
79 | 0 | Marionette.addCommand({ |
80 | name: 'executeAsync', | |
81 | request: { | |
82 | to: ':marionetteId', | |
83 | session: ':sessionId', | |
84 | name: 'executeAsyncScript', | |
85 | parameters: { | |
86 | script: ':value', | |
87 | args: ':args', | |
88 | newSandbox: true, | |
89 | specialPowers: true | |
90 | } | |
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 | 1 | 'use strict'; |
26 | ||
27 | /** | |
28 | * Frame related Marionette commands | |
29 | * see [JsonProtocol](https://wiki.mozilla.org/Auto-tools/Projects/Marionette/JSON_Protocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class Frame | |
33 | * @namespace FirefoxDriver.Commands.Marionette | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function (Marionette) { |
37 | ||
38 | /** | |
39 | * Change focus to another frame on the page. | |
40 | * If the frame id is null, the server should switch to the page's default content. | |
41 | * | |
42 | * @method frame | |
43 | */ | |
44 | ||
45 | 0 | Marionette.addCommand({ |
46 | name: 'frame', | |
47 | request: { | |
48 | to: ':marionetteId', | |
49 | session: ':sessionId', | |
50 | name: 'switchToFrame', | |
51 | parameters: { | |
52 | element: ':elementId', | |
53 | focus: true | |
54 | } | |
55 | } | |
56 | }); | |
57 | ||
58 | }; | |
59 |
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 | * IME related Marionette commands | |
29 | * see [JsonProtocol](https://wiki.mozilla.org/Auto-tools/Projects/Marionette/JSON_Protocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class IME | |
33 | * @namespace FirefoxDriver.Commands.Marionette | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function (Marionette) { |
37 | ||
38 | /** | |
39 | * Query the server's current status. | |
40 | * The server should respond with a general "HTTP 200 OK" response if it is alive and accepting commands. | |
41 | * The response body should be a JSON object describing the state of the server. | |
42 | * All server implementations should return two basic objects describing the server's current platform | |
43 | * and when the server was built. All fields are optional; if omitted, the client should assume the value is uknown. | |
44 | * Furthermore, server implementations may include additional fields not listed here. | |
45 | * | |
46 | * @method status | |
47 | */ | |
48 | ||
49 | 0 | Marionette.addCommand({ |
50 | name: 'status', | |
51 | request: { | |
52 | to: ':marionetteId', | |
53 | name: 'getStatus' | |
54 | } | |
55 | }); | |
56 | ||
57 | }; | |
58 |
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 | * Interaction related Marionette commands | |
29 | * see [JsonProtocol](https://wiki.mozilla.org/Auto-tools/Projects/Marionette/JSON_Protocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class Interaction | |
33 | * @namespace FirefoxDriver.Commands.Marionette | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function () { |
37 | ||
38 | }; | |
39 |
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 | * Page related Marionette commands | |
29 | * see [JsonProtocol](https://wiki.mozilla.org/Auto-tools/Projects/Marionette/JSON_Protocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class Page | |
33 | * @namespace FirefoxDriver.Commands.Marionette | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function (Marionette) { |
37 | ||
38 | /** | |
39 | * Get the current page source | |
40 | * | |
41 | * @method source | |
42 | */ | |
43 | ||
44 | 0 | Marionette.addCommand({ |
45 | name: 'source', | |
46 | request: { | |
47 | to: ':marionetteId', | |
48 | session: ':sessionId', | |
49 | type: 'getPageSource' | |
50 | } | |
51 | }); | |
52 | ||
53 | /** | |
54 | * Get the current page title | |
55 | * | |
56 | * @method title | |
57 | */ | |
58 | ||
59 | 0 | Marionette.addCommand({ |
60 | name: 'title', | |
61 | request: { | |
62 | to: ':marionetteId', | |
63 | session: ':sessionId', | |
64 | type: 'getTitle' | |
65 | } | |
66 | }); | |
67 | ||
68 | /** | |
69 | * Get the current geo location | |
70 | * | |
71 | * @method geoLocation | |
72 | */ | |
73 | ||
74 | 0 | Marionette.addCommand({ |
75 | name: 'geoLocation', | |
76 | implemented: false | |
77 | }); | |
78 | ||
79 | /** | |
80 | * Set the geo location | |
81 | * | |
82 | * @method setGeoLocation | |
83 | */ | |
84 | ||
85 | 0 | Marionette.addCommand({ |
86 | name: 'setGeoLocation', | |
87 | implemented: false | |
88 | }); | |
89 | ||
90 | }; | |
91 |
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 | * Screenshot related Marionette commands | |
29 | * see [JsonProtocol](https://wiki.mozilla.org/Auto-tools/Projects/Marionette/JSON_Protocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class Screenshot | |
33 | * @namespace FirefoxDriver.Commands.Marionette | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function (Marionette) { |
37 | ||
38 | /** | |
39 | * Returns the current visible screen as a base64 png | |
40 | * | |
41 | * @method screenshot | |
42 | */ | |
43 | ||
44 | 0 | Marionette.addCommand({ |
45 | name: 'screenshot', | |
46 | request: { | |
47 | to: ':marionetteId', | |
48 | session: ':sessionId', | |
49 | name: 'screenShot', | |
50 | parameters: {} | |
51 | } | |
52 | }); | |
53 | ||
54 | }; | |
55 |
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 | * Session related Marionette commands | |
29 | * see [JsonProtocol](https://wiki.mozilla.org/Auto-tools/Projects/Marionette/JSON_Protocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class Session | |
33 | * @namespace FirefoxDriver.Commands.Marionette | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function (Marionette) { |
37 | ||
38 | /** | |
39 | * Gets the marionette id for the current testing session | |
40 | * | |
41 | * @method getMarionetteID | |
42 | */ | |
43 | ||
44 | 0 | Marionette.addCommand({ |
45 | name: 'getMarionetteID', | |
46 | request: { | |
47 | to: 'root', | |
48 | name: 'getMarionetteID' | |
49 | } | |
50 | }); | |
51 | ||
52 | /** | |
53 | * Gets the session id for the current testing session | |
54 | * | |
55 | * @method getSession | |
56 | */ | |
57 | ||
58 | 0 | Marionette.addCommand({ |
59 | name: 'getSession', | |
60 | request: { | |
61 | to: ':marionetteId', | |
62 | name: 'newSession' | |
63 | } | |
64 | }); | |
65 | ||
66 | /** | |
67 | * Retrieve the capabilities of the specified session. | |
68 | * | |
69 | * @method session | |
70 | */ | |
71 | ||
72 | 0 | Marionette.addCommand({ |
73 | name: 'session', | |
74 | request: { | |
75 | to: ':marionetteId', | |
76 | session: ':sessionId', | |
77 | name: 'getSessionCapabilities' | |
78 | } | |
79 | }); | |
80 | ||
81 | }; | |
82 |
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 | * Storage related Marionette commands | |
29 | * see [JsonProtocol](https://wiki.mozilla.org/Auto-tools/Projects/Marionette/JSON_Protocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class Storage | |
33 | * @namespace FirefoxDriver.Commands.Marionette | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function () { |
37 | ||
38 | }; | |
39 |
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 | * Timeout related Marionette commands | |
29 | * see [JsonProtocol](https://wiki.mozilla.org/Auto-tools/Projects/Marionette/JSON_Protocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class Timeout | |
33 | * @namespace FirefoxDriver.Commands.Marionette | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function (Marionette) { |
37 | ||
38 | /** | |
39 | * | |
40 | */ | |
41 | ||
42 | 0 | Marionette.addCommand({ |
43 | name: 'implicitWait', | |
44 | request: { | |
45 | to: ':marionetteId', | |
46 | session: ':sessionId', | |
47 | value: ':timeout', | |
48 | name: 'setSearchTimeout' | |
49 | } | |
50 | }); | |
51 | ||
52 | }; | |
53 |
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 | * Url related Marionette commands | |
29 | * see [JsonProtocol](https://wiki.mozilla.org/Auto-tools/Projects/Marionette/JSON_Protocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class Url | |
33 | * @namespace FirefoxDriver.Commands.Marionette | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function (Marionette) { |
37 | ||
38 | /** | |
39 | * Navigate to a new URL | |
40 | * | |
41 | * @method open | |
42 | */ | |
43 | ||
44 | 0 | Marionette.addCommand({ |
45 | name: 'open', | |
46 | params: ['url'], | |
47 | request: { | |
48 | to: ':marionetteId', | |
49 | session: ':sessionId', | |
50 | name: 'goUrl', | |
51 | parameters: { | |
52 | url: ':url' | |
53 | } | |
54 | } | |
55 | }); | |
56 | ||
57 | /** | |
58 | * Retrieve the URL of the current page | |
59 | * | |
60 | * @method url | |
61 | */ | |
62 | ||
63 | 0 | Marionette.addCommand({ |
64 | name: 'url', | |
65 | request: { | |
66 | to: ':marionetteId', | |
67 | session: ':sessionId', | |
68 | name: 'getUrl' | |
69 | } | |
70 | }); | |
71 | ||
72 | /** | |
73 | * Navigate backwards in the browser history, if possible | |
74 | * | |
75 | * @method back | |
76 | */ | |
77 | ||
78 | 0 | Marionette.addCommand({ |
79 | name: 'back', | |
80 | request: { | |
81 | to: ':marionetteId', | |
82 | session: ':sessionId', | |
83 | name: 'goBack' | |
84 | } | |
85 | }); | |
86 | ||
87 | /** | |
88 | * Navigate forwards in the browser history, if possible. | |
89 | * | |
90 | * @method forward | |
91 | */ | |
92 | ||
93 | 0 | Marionette.addCommand({ |
94 | name: 'forward', | |
95 | request: { | |
96 | to: ':marionetteId', | |
97 | session: ':sessionId', | |
98 | name: 'goForward' | |
99 | } | |
100 | }); | |
101 | ||
102 | /** | |
103 | * Refresh the current page | |
104 | * | |
105 | * @method refresh | |
106 | */ | |
107 | ||
108 | 0 | Marionette.addCommand({ |
109 | name: 'refresh', | |
110 | request: { | |
111 | to: ':marionetteId', | |
112 | session: ':sessionId', | |
113 | name: 'refresh' | |
114 | } | |
115 | }); | |
116 | ||
117 | }; | |
118 |
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 | * Window related Marionette commands | |
29 | * see [JsonProtocol](https://wiki.mozilla.org/Auto-tools/Projects/Marionette/JSON_Protocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class Window | |
33 | * @namespace FirefoxDriver.Commands.Marionette | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function (Marionette) { |
37 | ||
38 | /** | |
39 | * Gets the current window size | |
40 | * | |
41 | * @method windowSize | |
42 | */ | |
43 | ||
44 | 0 | Marionette.addCommand({ |
45 | name: 'windowSize', | |
46 | request: { | |
47 | to: ':marionetteId', | |
48 | session: ':sessionId', | |
49 | name: 'executeScript', | |
50 | value: ':value', | |
51 | newSandbox: false | |
52 | } | |
53 | }); | |
54 | ||
55 | /** | |
56 | * Returns the current window handle | |
57 | * | |
58 | * @method windowHandles | |
59 | */ | |
60 | ||
61 | 0 | Marionette.addCommand({ |
62 | name: 'windowHandles', | |
63 | request: { | |
64 | to: ':marionetteId', | |
65 | session: ':sessionId', | |
66 | name: 'getWindows' | |
67 | } | |
68 | }); | |
69 | ||
70 | /** | |
71 | * Switches the active window | |
72 | * | |
73 | * @method changeWindow | |
74 | */ | |
75 | ||
76 | 0 | Marionette.addCommand({ |
77 | name: 'changeWindow', | |
78 | request: { | |
79 | to: ':marionetteId', | |
80 | session: ':sessionId', | |
81 | name: 'switchToWindow', | |
82 | parameters: { | |
83 | value: ':value' | |
84 | } | |
85 | } | |
86 | }); | |
87 | ||
88 | }; | |
89 |
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 | * Cookie related WebDriver endpoints | |
29 | * see [JsonWireProtocol](https://code.google.com/p/selenium/wiki/JsonWireProtocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class Cookie | |
33 | * @namespace FirefoxDriver.Commands.WebDriver | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function (Driver) { |
37 | ||
38 | /** | |
39 | * Set a cookie. If the cookie path is not specified, it should be set to "/". | |
40 | * Likewise, if the domain is omitted, it should default to the current page's domain. | |
41 | * | |
42 | * @method cookies | |
43 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/cookie | |
44 | * @param {GET} sessionId ID of the session to route the command to | |
45 | * @param {POST} cookie A JSON object defining the cookie to add. | |
46 | */ | |
47 | ||
48 | 0 | Driver.addCommand({ |
49 | name: 'cookies', | |
50 | url: '/session/:sessionId/cookie', | |
51 | method: 'post', | |
52 | params: {cookie: 'cookie'}, | |
53 | onRequest: function (req, res) { | |
54 | // load the marionette connection id & then request the session id | |
55 | 0 | this.events.emit('marionette:cmd:cookies', {'sessionId': req.params.sessionId, 'cookie': {'name': req.body.cookie.name, 'value': req.body.cookie.value}}); |
56 | 0 | this.events.on('marionette:cmd:cookies:response', function (data) { |
57 | 0 | data = JSON.parse(data); |
58 | 0 | var answer = { |
59 | sessionId: req.params.sessionId, | |
60 | status: 0, | |
61 | value: data.value | |
62 | }; | |
63 | ||
64 | 0 | res.status(200); |
65 | 0 | res.send(JSON.stringify(answer)); |
66 | }.bind(this)); | |
67 | } | |
68 | }); | |
69 | ||
70 | /** | |
71 | * Retrieve all cookies visible to the current page. | |
72 | * | |
73 | * @method getCookies | |
74 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/cookie | |
75 | * @param {GET} sessionId ID of the session to route the command to | |
76 | */ | |
77 | ||
78 | 0 | Driver.addCommand({ |
79 | name: 'getCookies', | |
80 | url: '/session/:sessionId/cookie', | |
81 | method: 'get' | |
82 | }); | |
83 | ||
84 | /** | |
85 | * Delete all cookies visible to the current page. | |
86 | * | |
87 | * @method deleteCookies | |
88 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#DELETE_/session/:sessionId/cookie | |
89 | * @param {GET} sessionId ID of the session to route the command to | |
90 | */ | |
91 | ||
92 | 0 | Driver.addCommand({ |
93 | name: 'deleteCookies', | |
94 | url: '/session/:sessionId/cookie', | |
95 | method: 'del' | |
96 | }); | |
97 | ||
98 | /** | |
99 | * Delete the cookie with the given name. | |
100 | * This command should be a no-op if there is no such cookie visible to the current page. | |
101 | * | |
102 | * @method deleteCookie | |
103 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#DELETE_/session/:sessionId/cookie | |
104 | * @param {GET} sessionId ID of the session to route the command to | |
105 | */ | |
106 | ||
107 | 0 | Driver.addCommand({ |
108 | name: 'deleteCookie', | |
109 | url: '/session/:sessionId/cookie/:name', | |
110 | method: 'del' | |
111 | }); | |
112 | ||
113 | }; | |
114 |
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 | * Element related WebDriver endpoints | |
29 | * see [JsonWireProtocol](https://code.google.com/p/selenium/wiki/JsonWireProtocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class Element | |
33 | * @namespace FirefoxDriver.Commands.WebDriver | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function (Driver) { |
37 | ||
38 | // check if the driver helper literal has been created yet | |
39 | 0 | if (!Driver._helper) { |
40 | 0 | Driver._helper = {}; |
41 | } | |
42 | ||
43 | // Helper | |
44 | // ------ | |
45 | ||
46 | /** | |
47 | * Parses an element return value | |
48 | * | |
49 | * @method parseElement | |
50 | * @param {object} element Marionette return value of an element call | |
51 | * @return {object|number} Webdriver compatible element response | |
52 | * @private | |
53 | */ | |
54 | ||
55 | 0 | Driver._helper.parseElement = function (element) { |
56 | 0 | element = JSON.parse(element); |
57 | 0 | return (!element.value) ? -1 : {ELEMENT: element.value.ELEMENT}; |
58 | }; | |
59 | ||
60 | /** | |
61 | * Parses multi elements return value | |
62 | * | |
63 | * @method parseElements | |
64 | * @param {object} element Marionette return value of an elements call | |
65 | * @return {object|number} Webdriver compatible elements response | |
66 | * @private | |
67 | */ | |
68 | ||
69 | 0 | Driver._helper.parseElements = function (elements) { |
70 | 0 | elements = JSON.parse(elements); |
71 | 0 | if (!elements.value) { |
72 | 0 | return -1; |
73 | } | |
74 | ||
75 | 0 | var dt = []; |
76 | 0 | elements.value.forEach(function (el) { |
77 | 0 | dt.push({ELEMENT: el}); |
78 | }); | |
79 | ||
80 | 0 | return dt; |
81 | }; | |
82 | ||
83 | /** | |
84 | * Generic multi elements response handler | |
85 | * | |
86 | * @method multiElementResponse | |
87 | * @param {object} req Original request | |
88 | * @param {object} res Original response | |
89 | * @private | |
90 | */ | |
91 | ||
92 | 0 | Driver._helper.multiElementResponse = function (req, res, elements) { |
93 | 0 | var answer = { |
94 | sessionId: req.params.sessionId, | |
95 | status: 0, | |
96 | value: Driver._helper.parseElements(elements) | |
97 | }; | |
98 | ||
99 | 0 | res.status(200); |
100 | 0 | res.send(JSON.stringify(answer)); |
101 | }; | |
102 | ||
103 | /** | |
104 | * Generic single element response handler | |
105 | * | |
106 | * @method singleElementResponse | |
107 | * @param {object} req Original request | |
108 | * @param {object} res Original response | |
109 | * @private | |
110 | */ | |
111 | ||
112 | 0 | Driver._helper.singleElementResponse = function (req, res, element) { |
113 | 0 | var answer = { |
114 | sessionId: req.params.sessionId, | |
115 | status: 0, | |
116 | value: Driver._helper.parseElement(element) | |
117 | }; | |
118 | ||
119 | 0 | res.status(200); |
120 | 0 | res.send(JSON.stringify(answer)); |
121 | }; | |
122 | ||
123 | /** | |
124 | * Search for an element on the page, starting from the document root. | |
125 | * The located element will be returned as a WebElement JSON object. | |
126 | * | |
127 | * @method element | |
128 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element | |
129 | * @param {GET} sessionId ID of the session to route the command to | |
130 | * @param {POST} using The locator strategy to use. // Not yet supported | |
131 | * @param {POST} value The The search target. | |
132 | */ | |
133 | ||
134 | 0 | Driver.addCommand({ |
135 | name: 'element', | |
136 | url: '/session/:sessionId/element', | |
137 | method: 'post', | |
138 | onRequest: function (req, res) { | |
139 | // load the marionette connection id & then request the session id | |
140 | 0 | this.events.emit('marionette:cmd:element', {'sessionId': req.params.sessionId, 'selector': req.body.value}); |
141 | 0 | this.events.on('marionette:cmd:element:response', Driver._helper.singleElementResponse.bind(this, req, res)); |
142 | } | |
143 | }); | |
144 | ||
145 | /** | |
146 | * Search for an element on the page, starting from the identified element. | |
147 | * The located element will be returned as a WebElement JSON object. | |
148 | * The table below lists the locator strategies that each server should support. | |
149 | * Each locator must return the first matching element located in the DOM. | |
150 | * | |
151 | * @method childElement | |
152 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/:id/element | |
153 | * @param {GET} sessionId ID of the session to route the command to | |
154 | * @param {GET} elementId ID of the element to route the command to | |
155 | * @param {POST} using The locator strategy to use. // Not yet supported | |
156 | * @param {POST} value The The search target. | |
157 | */ | |
158 | ||
159 | 0 | Driver.addCommand({ |
160 | name: 'childElement', | |
161 | url: '/session/:sessionId/element/:elementId/element', | |
162 | method: 'post', | |
163 | onRequest: function (req, res) { | |
164 | // load the marionette connection id & then request the session id | |
165 | 0 | this.events.emit('marionette:cmd:childElement', {'sessionId': req.params.sessionId, 'elementId': req.params.elementId, 'selector': req.body.value}); |
166 | 0 | this.events.on('marionette:cmd:childElement:response', Driver._helper.singleElementResponse.bind(this, req, res)); |
167 | } | |
168 | }); | |
169 | ||
170 | /** | |
171 | * Search for multiple elements on the page, starting from the document root. | |
172 | * The located element will be returned as a WebElement JSON object. | |
173 | * | |
174 | * @method elements | |
175 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/elements | |
176 | * @param {GET} sessionId ID of the session to route the command to | |
177 | * @param {POST} using The locator strategy to use. // Not yet supported | |
178 | * @param {POST} value The The search target. | |
179 | */ | |
180 | ||
181 | 0 | Driver.addCommand({ |
182 | name: 'elements', | |
183 | url: '/session/:sessionId/elements', | |
184 | method: 'post', | |
185 | onRequest: function (req, res) { | |
186 | // load the marionette connection id & then request the session id | |
187 | 0 | this.events.emit('marionette:cmd:elements', {'sessionId': req.params.sessionId, 'selector': req.body.value}); |
188 | 0 | this.events.on('marionette:cmd:elements:response', Driver._helper.multiElementResponse.bind(this, req, res)); |
189 | } | |
190 | }); | |
191 | ||
192 | /** | |
193 | * Search for multiple elements on the page, starting from the identified element. | |
194 | * The located elements will be returned as a WebElement JSON objects. | |
195 | * The table below lists the locator strategies that each server should support. | |
196 | * Elements should be returned in the order located in the DOM. | |
197 | * | |
198 | * @method childElements | |
199 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/elements/:id/elements | |
200 | * @param {GET} sessionId ID of the session to route the command to | |
201 | * @param {GET} elementId ID of the element to route the command to | |
202 | * @param {POST} using The locator strategy to use. // Not yet supported | |
203 | * @param {POST} value The The search target. | |
204 | */ | |
205 | ||
206 | 0 | Driver.addCommand({ |
207 | name: 'childElements', | |
208 | url: '/session/:sessionId/elements/:elementId/elements', | |
209 | method: 'post', | |
210 | onRequest: function (req, res) { | |
211 | // load the marionette connection id & then request the session id | |
212 | 0 | this.events.emit('marionette:cmd:childElements', {'sessionId': req.params.sessionId, 'elementId': req.params.elementId, 'selector': req.body.value}); |
213 | 0 | this.events.on('marionette:cmd:childElements:response', Driver._helper.multiElementResponse.bind(this, req, res)); |
214 | } | |
215 | }); | |
216 | ||
217 | /** | |
218 | * Click on an element. | |
219 | * | |
220 | * @method click | |
221 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/click | |
222 | * @param {GET} sessionId ID of the session to route the command to | |
223 | * @param {GET} elementId ID of the element to route the command to | |
224 | */ | |
225 | ||
226 | 0 | Driver.addCommand({ |
227 | name: 'click', | |
228 | url: '/session/:sessionId/element/:elementId/click', | |
229 | method: 'post', | |
230 | timeout: 1500 | |
231 | }); | |
232 | ||
233 | /** | |
234 | * Submit a FORM element. | |
235 | * The submit command may also be applied to any element that is a descendant of a FORM element. | |
236 | * | |
237 | * @method submit | |
238 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/submit | |
239 | * @param {GET} sessionId ID of the session to route the command to | |
240 | * @param {GET} elementId ID of the element to route the command to | |
241 | */ | |
242 | ||
243 | 0 | Driver.addCommand({ |
244 | name: 'submit', | |
245 | url: '/session/:sessionId/element/:elementId/submit', | |
246 | method: 'post', | |
247 | timeout: 1000 | |
248 | }); | |
249 | ||
250 | /** | |
251 | * Send a sequence of key strokes to an element | |
252 | * | |
253 | * @method value | |
254 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/value | |
255 | * @param {GET} sessionId ID of the session to route the command to | |
256 | * @param {GET} elementId ID of the element to route the command to | |
257 | * @param {POST} value The keys sequence to be sent | |
258 | */ | |
259 | ||
260 | 0 | Driver.addCommand({ |
261 | name: 'val', | |
262 | url: '/session/:sessionId/element/:elementId/value', | |
263 | method: 'post', | |
264 | params: {value: 'value'} | |
265 | }); | |
266 | ||
267 | /** | |
268 | * Clears the contents of an element | |
269 | * | |
270 | * @method value | |
271 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/value | |
272 | * @param {GET} sessionId ID of the session to route the command to | |
273 | * @param {GET} elementId ID of the element to route the command to | |
274 | * @param {POST} value The keys sequence to be sent | |
275 | */ | |
276 | ||
277 | 0 | Driver.addCommand({ |
278 | name: 'clear', | |
279 | url: '/session/:sessionId/element/:elementId/clear', | |
280 | method: 'post' | |
281 | }); | |
282 | ||
283 | 0 | Driver.addCommand({ |
284 | name: 'submit', | |
285 | url: '/session/:sessionId/element/:elementId/submit', | |
286 | method: 'post' | |
287 | }); | |
288 | ||
289 | /** | |
290 | * Send a sequence of key strokes to the active element. | |
291 | * This command is similar to the send keys command in every aspect except the implicit termination: | |
292 | * The modifiers are not released at the end of the call. | |
293 | * Rather, the state of the modifier keys is kept between calls, | |
294 | * so mouse interactions can be performed while modifier keys are depressed. | |
295 | * | |
296 | * @method keys | |
297 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/keys | |
298 | * @param {GET} sessionId ID of the session to route the command to | |
299 | * @param {POST} value The keys sequence to be sent | |
300 | */ | |
301 | ||
302 | 0 | Driver.addCommand({ |
303 | name: 'keys', | |
304 | url: '/session/:sessionId/keys', | |
305 | method: 'post', | |
306 | params: {value: 'value'} | |
307 | }); | |
308 | ||
309 | /** | |
310 | * Returns the visible text for the element. | |
311 | * | |
312 | * @method text | |
313 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/text | |
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 | */ | |
317 | ||
318 | 0 | Driver.addCommand({ |
319 | name: 'text', | |
320 | url: '/session/:sessionId/element/:elementId/text', | |
321 | method: 'get' | |
322 | }); | |
323 | ||
324 | /** | |
325 | * Get the value of an element's attribute. | |
326 | * | |
327 | * @method attribute | |
328 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/attribute/:name | |
329 | * @param {GET} sessionId ID of the session to route the command to | |
330 | * @param {GET} elementId ID of the element to route the command to | |
331 | * @param {GET} attr Attribute that should be fetched | |
332 | */ | |
333 | ||
334 | 0 | Driver.addCommand({ |
335 | name: 'attribute', | |
336 | url: '/session/:sessionId/element/:elementId/attribute/:attr', | |
337 | method: 'get' | |
338 | }); | |
339 | ||
340 | /** | |
341 | * Determine an element's location on the page. | |
342 | * 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 displayed | |
346 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/displayed | |
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 | 0 | Driver.addCommand({ |
352 | name: 'displayed', | |
353 | url: '/session/:sessionId/element/:elementId/displayed', | |
354 | method: 'get' | |
355 | }); | |
356 | ||
357 | /** | |
358 | * Query for an element's tag name | |
359 | * | |
360 | * @method tagName | |
361 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/name | |
362 | * @param {GET} sessionId ID of the session to route the command to | |
363 | * @param {GET} elementId ID of the element to route the command to | |
364 | */ | |
365 | ||
366 | 0 | Driver.addCommand({ |
367 | name: 'tagName', | |
368 | url: '/session/:sessionId/element/:elementId/name', | |
369 | method: 'get' | |
370 | }); | |
371 | ||
372 | /** | |
373 | * Clear a TEXTAREA or text INPUT element's value | |
374 | * | |
375 | * @method clear | |
376 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element/:id/clear | |
377 | * @param {GET} sessionId ID of the session to route the command to | |
378 | * @param {GET} elementId ID of the element to route the command to | |
379 | */ | |
380 | ||
381 | 0 | Driver.addCommand({ |
382 | name: 'clear', | |
383 | url: '/session/:sessionId/element/:elementId/clear', | |
384 | method: 'post' | |
385 | }); | |
386 | ||
387 | /** | |
388 | * Determine if an OPTION element, or an INPUT element of type checkbox or radiobutton is currently selected | |
389 | * | |
390 | * @method selected | |
391 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/selected | |
392 | * @param {GET} sessionId ID of the session to route the command to | |
393 | * @param {GET} elementId ID of the element to route the command to | |
394 | */ | |
395 | ||
396 | 0 | Driver.addCommand({ |
397 | name: 'selected', | |
398 | url: '/session/:sessionId/element/:elementId/selected', | |
399 | method: 'get' | |
400 | }); | |
401 | ||
402 | /** | |
403 | * Determine if an element is currently enabled | |
404 | * | |
405 | * @method enabled | |
406 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/enabled | |
407 | * @param {GET} sessionId ID of the session to route the command to | |
408 | * @param {GET} elementId ID of the element to route the command to | |
409 | */ | |
410 | ||
411 | 0 | Driver.addCommand({ |
412 | name: 'enabled', | |
413 | url: '/session/:sessionId/element/:elementId/enabled', | |
414 | method: 'get' | |
415 | }); | |
416 | ||
417 | /** | |
418 | * Test if two element IDs refer to the same DOM element | |
419 | * | |
420 | * @method equals | |
421 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/equals/:other | |
422 | * @param {GET} sessionId ID of the session to route the command to | |
423 | * @param {GET} elementId ID of the element to route the command to | |
424 | * @param {GET} other ID of the element to compare | |
425 | */ | |
426 | ||
427 | 0 | Driver.addCommand({ |
428 | name: 'equals', | |
429 | url: '/session/:sessionId/element/:elementId/equals/:other', | |
430 | method: 'get' | |
431 | }); | |
432 | ||
433 | /** | |
434 | * Determine an element's location on the page. The point (0, 0) refers to the upper-left corner of the page. | |
435 | * The element's coordinates are returned as a JSON object with x and y properties. | |
436 | * | |
437 | * @method location | |
438 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/location | |
439 | * @param {GET} sessionId ID of the session to route the command to | |
440 | * @param {GET} elementId ID of the element to route the command to | |
441 | */ | |
442 | ||
443 | 0 | Driver.addCommand({ |
444 | name: 'location', | |
445 | url: '/session/:sessionId/element/:elementId/location', | |
446 | method: 'get' | |
447 | }); | |
448 | ||
449 | /** | |
450 | * Determine an element's location on the screen once it has been scrolled into view. | |
451 | * Note: This is considered an internal command and should only be used to determine an element's location for correctly generating native events. | |
452 | * | |
453 | * @method locationInView | |
454 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/location_in_view | |
455 | * @param {GET} sessionId ID of the session to route the command to | |
456 | * @param {GET} elementId ID of the element to route the command to | |
457 | */ | |
458 | ||
459 | 0 | Driver.addCommand({ |
460 | name: 'locationInView', | |
461 | url: '/session/:sessionId/element/:elementId/location_in_view', | |
462 | method: 'get' | |
463 | }); | |
464 | ||
465 | /** | |
466 | * Determine an element's size in pixels. | |
467 | * The size will be returned as a JSON object with width and height properties. | |
468 | * | |
469 | * @method size | |
470 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/size | |
471 | * @param {GET} sessionId ID of the session to route the command to | |
472 | * @param {GET} elementId ID of the element to route the command to | |
473 | */ | |
474 | ||
475 | 0 | Driver.addCommand({ |
476 | name: 'size', | |
477 | url: '/session/:sessionId/element/:elementId/size', | |
478 | method: 'get' | |
479 | }); | |
480 | ||
481 | /** | |
482 | * Get the element on the page that currently has focus. | |
483 | * The element will be returned as a WebElement JSON object. | |
484 | * | |
485 | * @method active | |
486 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/active | |
487 | * @param {GET} sessionId ID of the session to route the command to | |
488 | * @param {GET} elementId ID of the element to route the command to | |
489 | */ | |
490 | ||
491 | 0 | Driver.addCommand({ |
492 | name: 'active', | |
493 | url: '/session/:sessionId/element/:elementId/active', | |
494 | method: 'get' | |
495 | }); | |
496 | ||
497 | /** | |
498 | * Get the element on the page that currently has focus. | |
499 | * The element will be returned as a WebElement JSON object. | |
500 | * | |
501 | * @method elementInfo | |
502 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id | |
503 | * @param {GET} sessionId ID of the session to route the command to | |
504 | * @param {GET} elementId ID of the element to route the command to | |
505 | */ | |
506 | ||
507 | 0 | Driver.addCommand({ |
508 | name: 'elementInfo', | |
509 | url: '/session/:sessionId/element/:elementId', | |
510 | method: 'get' | |
511 | }); | |
512 | ||
513 | /** | |
514 | * Query the value of an element's computed CSS property. | |
515 | * The CSS property to query should be specified using the CSS property name, | |
516 | * not the JavaScript property name (e.g. background-color instead of backgroundColor). | |
517 | * | |
518 | * @method cssProperty | |
519 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/size | |
520 | * @param {GET} sessionId ID of the session to route the command to | |
521 | * @param {GET} elementId ID of the element to route the command to | |
522 | * @param {GET} propertyName Name of the css property to fetch | |
523 | */ | |
524 | ||
525 | 0 | Driver.addCommand({ |
526 | name: 'cssProperty', | |
527 | url: '/session/:sessionId/element/:elementId/css/:propertyName', | |
528 | method: 'get' | |
529 | }); | |
530 | ||
531 | }; | |
532 |
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 | * ScriptExecutor related WebDriver endpoints | |
29 | * see [JsonWireProtocol](https://code.google.com/p/selenium/wiki/JsonWireProtocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class ScriptExecutor | |
33 | * @namespace FirefoxDriver.Commands.WebDriver | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function (Driver) { |
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 | 0 | Driver.addCommand({ |
54 | name: 'execute', | |
55 | url: '/session/:sessionId/execute', | |
56 | method: 'post', | |
57 | params: {value: 'script', args: 'args'}, | |
58 | onRequest: function (req, res) { | |
59 | // load the marionette connection id & then request the session id | |
60 | 0 | this.events.emit('marionette:cmd:execute', {'sessionId': req.params.sessionId, 'value': req.body.script, 'args': req.body.args}); |
61 | 0 | this.events.on('marionette:cmd:execute:response', function (data) { |
62 | 0 | data = JSON.parse(data); |
63 | 0 | var answer = { |
64 | sessionId: req.params.sessionId, | |
65 | status: 0, | |
66 | value: data.value | |
67 | }; | |
68 | ||
69 | 0 | res.status(200); |
70 | 0 | res.send(JSON.stringify(answer)); |
71 | }.bind(this)); | |
72 | } | |
73 | }); | |
74 | ||
75 | /** | |
76 | * Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. | |
77 | * The executed script is assumed to be asynchronous and must signal that is done by invoking the provided callback, | |
78 | * which is always provided as the final argument to the function. The value to this callback will be returned to the client. | |
79 | * Asynchronous script commands may not span page loads. | |
80 | * If an unload event is fired while waiting for a script result, an error should be returned to the client. | |
81 | * | |
82 | * The script argument defines the script to execute in teh form of a function body. | |
83 | * The function will be invoked with the provided args array and the values may be accessed | |
84 | * via the arguments object in the order specified. | |
85 | * The final argument will always be a callback function that must be invoked to signal that the script has finished. | |
86 | * | |
87 | * @method executeAsync | |
88 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/execute_async | |
89 | * @param {GET} sessionId ID of the session to route the command to | |
90 | * @param {POST} script The script to execute. | |
91 | * @param {POST} args The script arguments. | |
92 | */ | |
93 | ||
94 | 0 | Driver.addCommand({ |
95 | name: 'executeAsync', | |
96 | url: '/session/:sessionId/execute_async', | |
97 | method: 'post', | |
98 | params: {script: 'script', args: 'args'} | |
99 | }); | |
100 | ||
101 | }; | |
102 |
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 | * Frame related WebDriver endpoints | |
29 | * see [JsonWireProtocol](https://code.google.com/p/selenium/wiki/JsonWireProtocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class Frame | |
33 | * @namespace FirefoxDriver.Commands.WebDriver | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function (Driver) { |
37 | ||
38 | /** | |
39 | * Change focus to another frame on the page. | |
40 | * If the frame id is null, the server should switch to the page's default content. | |
41 | * | |
42 | * @method frame | |
43 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/frame | |
44 | * @param {GET} sessionId ID of the session to route the command to | |
45 | * @param {POST} id Identifier for the frame to change focus to. | |
46 | */ | |
47 | ||
48 | 0 | Driver.addCommand({ |
49 | name: 'frame', | |
50 | url: '/session/:sessionId/frame', | |
51 | method: 'post', | |
52 | params: {id: 'id'} | |
53 | }); | |
54 | ||
55 | }; | |
56 |
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 | * Ime related WebDriver endpoints | |
29 | * see [JsonWireProtocol](https://code.google.com/p/selenium/wiki/JsonWireProtocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class Ime | |
33 | * @namespace FirefoxDriver.Commands.WebDriver | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function (Driver) { |
37 | ||
38 | /** | |
39 | * Query the server's current status. | |
40 | * The server should respond with a general "HTTP 200 OK" response if it is alive and accepting commands. | |
41 | * The response body should be a JSON object describing the state of the server. | |
42 | * All server implementations should return two basic objects describing the server's current platform | |
43 | * and when the server was built. All fields are optional; if omitted, the client should assume the value is uknown. | |
44 | * Furthermore, server implementations may include additional fields not listed here. | |
45 | * | |
46 | * @method status | |
47 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/status | |
48 | * @return {200} Always up | |
49 | */ | |
50 | ||
51 | 0 | Driver.addCommand({ |
52 | name: 'status', | |
53 | url: '/status', | |
54 | method: 'get', | |
55 | onRequest: function (req, res) { | |
56 | // load the status from marionette | |
57 | 0 | this.events.emit('marionette:cmd:status'); |
58 | ||
59 | // send out the raw status response | |
60 | 0 | this.events.on('marionette:cmd:status:response', function (data) { |
61 | 0 | data = JSON.parse(data); |
62 | 0 | res.send(JSON.stringify(data)); |
63 | }.bind(this)); | |
64 | } | |
65 | }); | |
66 | ||
67 | /** | |
68 | * List all available engines on the machine. | |
69 | * To use an engine, it has to be present in this list. | |
70 | * | |
71 | * @method availableEngines | |
72 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/ime/available_engines | |
73 | * @param {GET} sessionId ID of the session to route the command to | |
74 | */ | |
75 | ||
76 | 0 | Driver.addCommand({ |
77 | name: 'availableEngines', | |
78 | url: '/session/:sessionId/ime/available_engines', | |
79 | method: 'get' | |
80 | }); | |
81 | ||
82 | /** | |
83 | * Get the name of the active IME engine. | |
84 | * The name string is platform specific. | |
85 | * | |
86 | * @method activeEngine | |
87 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/ime/active_engine | |
88 | * @param {GET} sessionId ID of the session to route the command to | |
89 | */ | |
90 | ||
91 | 0 | Driver.addCommand({ |
92 | name: 'activeEngine', | |
93 | url: '/session/:sessionId/ime/active_engine', | |
94 | method: 'get' | |
95 | }); | |
96 | ||
97 | /** | |
98 | * Indicates whether IME input is active at the moment | |
99 | * | |
100 | * @method activatedEngine | |
101 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/ime/activated | |
102 | * @param {GET} sessionId ID of the session to route the command to | |
103 | */ | |
104 | ||
105 | 0 | Driver.addCommand({ |
106 | name: 'activatedEngine', | |
107 | url: '/session/:sessionId/ime/activated', | |
108 | method: 'get' | |
109 | }); | |
110 | ||
111 | /** | |
112 | * De-activates the currently-active IME engine | |
113 | * | |
114 | * @method deactivateEngine | |
115 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/ime/deactivate | |
116 | * @param {GET} sessionId ID of the session to route the command to | |
117 | */ | |
118 | ||
119 | 0 | Driver.addCommand({ |
120 | name: 'deactivateEngine', | |
121 | url: '/session/:sessionId/ime/deactivate', | |
122 | method: 'post' | |
123 | }); | |
124 | ||
125 | /** | |
126 | * Make an engines that is available (appears on the list returned by getAvailableEngines) active. | |
127 | * After this call, the engine will be added to the list of engines loaded in the IME daemon | |
128 | * and the input sent using sendKeys will be converted by the active engine. | |
129 | * Note that this is a platform-independent method of activating IME | |
130 | * (the platform-specific way being using keyboard shortcuts) | |
131 | * | |
132 | * @method activateEngine | |
133 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/ime/activate | |
134 | * @param {GET} sessionId ID of the session to route the command to | |
135 | * @param {POST} engine Name of the engine to activate | |
136 | */ | |
137 | ||
138 | 0 | Driver.addCommand({ |
139 | name: 'activateEngine', | |
140 | url: '/session/:sessionId/ime/activate', | |
141 | method: 'post', | |
142 | params: {engine: 'engine'} | |
143 | }); | |
144 | ||
145 | ||
146 | }; | |
147 |
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 | * Interaction related WebDriver endpoints | |
29 | * see [JsonWireProtocol](https://code.google.com/p/selenium/wiki/JsonWireProtocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class Interaction | |
33 | * @namespace FirefoxDriver.Commands.WebDriver | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function (Driver) { |
37 | ||
38 | /** | |
39 | * Move the mouse by an offset of the specificed element. | |
40 | * If no element is specified, the move is relative to the current mouse cursor. | |
41 | * If an element is provided but no offset, the mouse will be moved to the center of the element. | |
42 | * If the element is not visible, it will be scrolled into view. | |
43 | * | |
44 | * @method moveto | |
45 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/moveto | |
46 | * @param {GET} sessionId ID of the session to route the command to | |
47 | * @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. | |
48 | * @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. | |
49 | * @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. | |
50 | */ | |
51 | ||
52 | 0 | Driver.addCommand({ |
53 | name: 'moveto', | |
54 | url: '/session/:sessionId/moveto', | |
55 | method: 'post', | |
56 | params: {element: 'element', xoffset: 'xoffset', yoffset: 'yoffset'} | |
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 clickPage | |
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 | 0 | Driver.addCommand({ |
71 | name: 'clickPage', | |
72 | url: '/session/:sessionId/click', | |
73 | method: 'post', | |
74 | params: {button: 'button'} | |
75 | }); | |
76 | ||
77 | /** | |
78 | * Click and hold the left mouse button (at the coordinates set by the last moveto command). | |
79 | * Note that the next mouse-related command that should follow is buttonup. | |
80 | * Any other mouse command (such as click or another call to buttondown) will yield undefined behaviour. | |
81 | * | |
82 | * @method buttondown | |
83 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/buttondown | |
84 | * @param {GET} sessionId ID of the session to route the command to | |
85 | * @param {POST} button Which button, enum: {LEFT = 0, MIDDLE = 1 , RIGHT = 2}. Defaults to the left mouse button if not specified. | |
86 | */ | |
87 | ||
88 | 0 | Driver.addCommand({ |
89 | name: 'buttondown', | |
90 | url: '/session/:sessionId/buttondown', | |
91 | method: 'post', | |
92 | params: {button: 'button'} | |
93 | }); | |
94 | ||
95 | /** | |
96 | * Releases the mouse button previously held (where the mouse is currently at). | |
97 | * Must be called once for every buttondown command issued. | |
98 | * See the note in click and buttondown about implications of out-of-order commands. | |
99 | * | |
100 | * @method buttonup | |
101 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/buttonup | |
102 | * @param {GET} sessionId ID of the session to route the command to | |
103 | * @param {POST} button Which button, enum: {LEFT = 0, MIDDLE = 1 , RIGHT = 2}. Defaults to the left mouse button if not specified. | |
104 | */ | |
105 | ||
106 | 0 | Driver.addCommand({ |
107 | name: 'buttonup', | |
108 | url: '/session/:sessionId/buttonup', | |
109 | method: 'post', | |
110 | params: {button: 'button'} | |
111 | }); | |
112 | ||
113 | /** | |
114 | * Double-clicks at the current mouse coordinates (set by moveto). | |
115 | * | |
116 | * @method doubleclickPage | |
117 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/doubleclick | |
118 | * @param {GET} sessionId ID of the session to route the command to | |
119 | */ | |
120 | ||
121 | 0 | Driver.addCommand({ |
122 | name: 'doubleclickPage', | |
123 | url: '/session/:sessionId/doubleclick', | |
124 | method: 'post' | |
125 | }); | |
126 | ||
127 | /** | |
128 | * Single tap on the touch enabled device. | |
129 | * | |
130 | * @method tap | |
131 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/touch/click | |
132 | * @param {GET} sessionId ID of the session to route the command to | |
133 | */ | |
134 | ||
135 | 0 | Driver.addCommand({ |
136 | name: 'tap', | |
137 | url: '/session/:sessionId/touch/click', | |
138 | method: 'post' | |
139 | }); | |
140 | ||
141 | /** | |
142 | * Finger down on the screen. | |
143 | * | |
144 | * @method touchdown | |
145 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/touch/down | |
146 | * @param {GET} sessionId ID of the session to route the command to | |
147 | * @param {POST} x X coordinate on the screen. | |
148 | * @param {POST} y Y coordinate on the screen. | |
149 | */ | |
150 | ||
151 | 0 | Driver.addCommand({ |
152 | name: 'touchdown', | |
153 | url: '/session/:sessionId/touch/down', | |
154 | method: 'post', | |
155 | params: {x: 'x', y: 'y'} | |
156 | }); | |
157 | ||
158 | /** | |
159 | * Finger up on the screen. | |
160 | * | |
161 | * @method touchup | |
162 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/touch/up | |
163 | * @param {GET} sessionId ID of the session to route the command to | |
164 | * @param {POST} x X coordinate on the screen. | |
165 | * @param {POST} y Y coordinate on the screen. | |
166 | */ | |
167 | ||
168 | 0 | Driver.addCommand({ |
169 | name: 'touchup', | |
170 | url: '/session/:sessionId/touch/up', | |
171 | method: 'post', | |
172 | params: {x: 'x', y: 'y'} | |
173 | }); | |
174 | ||
175 | /** | |
176 | * Finger move on the screen. | |
177 | * | |
178 | * @method touchmove | |
179 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/touch/move | |
180 | * @param {GET} sessionId ID of the session to route the command to | |
181 | * @param {POST} x X coordinate on the screen. | |
182 | * @param {POST} y Y coordinate on the screen. | |
183 | */ | |
184 | ||
185 | 0 | Driver.addCommand({ |
186 | name: 'touchmove', | |
187 | url: '/session/:sessionId/touch/move', | |
188 | method: 'post', | |
189 | params: {x: 'x', y: 'y'} | |
190 | }); | |
191 | ||
192 | /** | |
193 | * Scroll on the touch screen using finger based motion events. | |
194 | * Use this command if you don't care where the scroll starts on the screen. | |
195 | * | |
196 | * @method touchscroll | |
197 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/touch/scroll | |
198 | * @param {GET} sessionId ID of the session to route the command to | |
199 | * @param {POST} x X coordinate on the screen. | |
200 | * @param {POST} y Y coordinate on the screen. | |
201 | */ | |
202 | ||
203 | 0 | Driver.addCommand({ |
204 | name: 'touchscroll', | |
205 | url: '/session/:sessionId/touch/scroll', | |
206 | method: 'post', | |
207 | params: {x: 'x', y: 'y'} | |
208 | }); | |
209 | ||
210 | /** | |
211 | * Double tap on the touch screen using finger motion events. | |
212 | * | |
213 | * @method doubletap | |
214 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/touch/doubleclick | |
215 | * @param {GET} sessionId ID of the session to route the command to | |
216 | */ | |
217 | ||
218 | 0 | Driver.addCommand({ |
219 | name: 'doubletap', | |
220 | url: '/session/:sessionId/touch/doubleclick', | |
221 | method: 'post' | |
222 | }); | |
223 | ||
224 | /** | |
225 | * Long press on the touch screen using finger motion events. | |
226 | * | |
227 | * @method longpress | |
228 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/touch/longclick | |
229 | * @param {GET} sessionId ID of the session to route the command to | |
230 | */ | |
231 | ||
232 | 0 | Driver.addCommand({ |
233 | name: 'longpress', | |
234 | url: '/session/:sessionId/touch/longclick', | |
235 | method: 'post' | |
236 | }); | |
237 | ||
238 | /** | |
239 | * Flick on the touch screen using finger motion events. | |
240 | * This flickcommand starts at a particulat screen location. | |
241 | * | |
242 | * @method flick | |
243 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/touch/flick | |
244 | * @param {GET} sessionId ID of the session to route the command to | |
245 | * @param {POST} element ID of the element where the flick starts | |
246 | * @param {POST} xoffset The x offset in pixels to flick by | |
247 | * @param {POST} yoffset The y offset in pixels to flick by | |
248 | * @param {POST} speed The speed in pixels per seconds | |
249 | */ | |
250 | ||
251 | 0 | Driver.addCommand({ |
252 | name: 'flick', | |
253 | url: '/session/:sessionId/touch/flick', | |
254 | method: 'post', | |
255 | params: {element: 'element', xoffset: 'xoffset', yoffset: 'yoffset' , speed: 'speed'} | |
256 | }); | |
257 | ||
258 | }; | |
259 |
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 | * Page related WebDriver endpoints | |
29 | * see [JsonWireProtocol](https://code.google.com/p/selenium/wiki/JsonWireProtocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class Page | |
33 | * @namespace FirefoxDriver.Commands.WebDriver | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function (Driver) { |
37 | ||
38 | /** | |
39 | * Get the current page source | |
40 | * | |
41 | * @method source | |
42 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/title | |
43 | * @param {GET} sessionId ID of the session to route the command to | |
44 | */ | |
45 | ||
46 | 0 | Driver.addCommand({ |
47 | name: 'source', | |
48 | url: '/session/:sessionId/source', | |
49 | method: 'get' | |
50 | }); | |
51 | ||
52 | /** | |
53 | * Get the current page title | |
54 | * | |
55 | * @method title | |
56 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/title | |
57 | * @param {GET} sessionId ID of the session to route the command to | |
58 | */ | |
59 | ||
60 | 0 | Driver.addCommand({ |
61 | name: 'title', | |
62 | url: '/session/:sessionId/title', | |
63 | method: 'get' | |
64 | }); | |
65 | ||
66 | /** | |
67 | * Get the current geo location | |
68 | * | |
69 | * @method geoLocation | |
70 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/location | |
71 | * @param {GET} sessionId ID of the session to route the command to | |
72 | */ | |
73 | ||
74 | 0 | Driver.addCommand({ |
75 | name: 'geoLocation', | |
76 | url: '/session/:sessionId/location', | |
77 | method: 'get' | |
78 | }); | |
79 | ||
80 | /** | |
81 | * Set the geo location | |
82 | * | |
83 | * @method setGeoLocation | |
84 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/location | |
85 | * @param {GET} sessionId ID of the session to route the command to | |
86 | * @param {POST} latitude The new location | |
87 | * @param {POST} longitude The new location | |
88 | * @param {POST} altitude The new location | |
89 | */ | |
90 | ||
91 | 0 | Driver.addCommand({ |
92 | name: 'location', | |
93 | url: '/session/:sessionId/location', | |
94 | method: 'post', | |
95 | params: {latitude: 'latitude', longitude: 'longitude', altitude: 'altitude'} | |
96 | }); | |
97 | ||
98 | }; | |
99 |
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 | * Screenshot related WebDriver endpoints | |
29 | * see [JsonWireProtocol](https://code.google.com/p/selenium/wiki/JsonWireProtocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class Screenshot | |
33 | * @namespace FirefoxDriver.Commands.WebDriver | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function (Driver) { |
37 | ||
38 | /** | |
39 | * Take a screenshot of the current page. | |
40 | * | |
41 | * @method screenshot | |
42 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/screenshot | |
43 | * @param {GET} sessionId ID of the session to route the command to | |
44 | */ | |
45 | ||
46 | 0 | Driver.addCommand({ |
47 | name: 'screenshot', | |
48 | url: '/session/:sessionId/screenshot', | |
49 | method: 'get' | |
50 | }); | |
51 | ||
52 | }; | |
53 |
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 | * Session related WebDriver endpoints | |
29 | * see [JsonWireProtocol](https://code.google.com/p/selenium/wiki/JsonWireProtocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class Session | |
33 | * @namespace FirefoxDriver.Commands.WebDriver | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function (Driver) { |
37 | ||
38 | /** | |
39 | * Create a new session. The server should attempt to create a session that most closely matches | |
40 | * the desired and required capabilities. Required capabilities have higher priority than | |
41 | * desired capabilities and must be set for the session to be created. | |
42 | * | |
43 | * @method createSession | |
44 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session | |
45 | * @param {POST} desiredCapabilities An object describing the session's desired capabilities. | |
46 | * @param {POST} requiredCapabilities An object describing the session's required capabilities | |
47 | * @return {303} See Other redirect to /session/:sessionId, where :sessionId is the ID of the newly created session. | |
48 | */ | |
49 | ||
50 | 0 | Driver.addCommand({ |
51 | name: 'createSession', | |
52 | url: '/session', | |
53 | method: 'post', | |
54 | onRequest: function (req, res) { | |
55 | // load the marionette connection id & then request the session id | |
56 | 0 | this.events.emit('marionette:cmd:getMarionetteID'); |
57 | 0 | this.events.on('marionette:cmd:getMarionetteID:response', function (connection) { |
58 | 0 | this.events.emit('marionette:setMarionetteID', connection.id); |
59 | 0 | this.events.emit('marionette:cmd:getSession'); |
60 | }.bind(this)); | |
61 | ||
62 | // send out the webdriver session response | |
63 | 0 | this.events.on('marionette:cmd:getSession:response', function (session) { |
64 | 0 | session = JSON.parse(session); |
65 | 0 | res.location('http://' + this.host + ':' + this.port + '/session/' + session.value); |
66 | 0 | res.end(); |
67 | }.bind(this)); | |
68 | } | |
69 | }); | |
70 | ||
71 | /** | |
72 | * Returns a list of the currently active sessions | |
73 | * | |
74 | * @method sessions | |
75 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/sessions | |
76 | */ | |
77 | ||
78 | 0 | Driver.addCommand({ |
79 | name: 'sessions', | |
80 | url: '/sessions', | |
81 | method: 'get' | |
82 | }); | |
83 | ||
84 | /** | |
85 | * Returns a list of the currently active sessions | |
86 | * | |
87 | * @method sessions | |
88 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/sessions | |
89 | */ | |
90 | ||
91 | 0 | Driver.addCommand({ |
92 | name: 'sessions', | |
93 | url: '/sessions', | |
94 | method: 'get' | |
95 | }); | |
96 | ||
97 | /** | |
98 | * Retrieve the capabilities of the specified 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 | 0 | Driver.addCommand({ |
106 | name: 'session', | |
107 | url: '/session/:sessionId', | |
108 | method: 'get' | |
109 | }); | |
110 | ||
111 | /** | |
112 | * Delete the session. | |
113 | * | |
114 | * @method session | |
115 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId | |
116 | * @param {GET} sessionId ID of the session to route the command to | |
117 | */ | |
118 | ||
119 | 0 | Driver.addCommand({ |
120 | name: 'deleteSession', | |
121 | url: '/session/:sessionId', | |
122 | method: 'del' | |
123 | }); | |
124 | ||
125 | }; | |
126 |
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 | * Storage related WebDriver endpoints | |
29 | * see [JsonWireProtocol](https://code.google.com/p/selenium/wiki/JsonWireProtocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class Storage | |
33 | * @namespace FirefoxDriver.Commands.WebDriver | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function (Driver) { |
37 | ||
38 | /** | |
39 | * Get all keys of the browsers local storage | |
40 | * | |
41 | * @method getLocalStorage | |
42 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/local_storage | |
43 | * @param {GET} sessionId ID of the session to route the command to | |
44 | */ | |
45 | ||
46 | 0 | Driver.addCommand({ |
47 | name: 'getLocalStorage', | |
48 | url: '/session/:sessionId/local_storage', | |
49 | method: 'get' | |
50 | }); | |
51 | ||
52 | /** | |
53 | * Set the storage item for the given key | |
54 | * | |
55 | * @method setLocalStorage | |
56 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/local_storage | |
57 | * @param {GET} sessionId ID of the session to route the command to | |
58 | * @param {POST} key The key to set | |
59 | * @param {POST} value The value to set | |
60 | */ | |
61 | ||
62 | 0 | Driver.addCommand({ |
63 | name: 'setLocalStorage', | |
64 | url: '/session/:sessionId/local_storage', | |
65 | method: 'post', | |
66 | params: {key: 'key', value: 'value'} | |
67 | }); | |
68 | ||
69 | /** | |
70 | * Clears the complete local storage | |
71 | * | |
72 | * @method clearLocalStorage | |
73 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#DELETE_/session/:sessionId/local_storage | |
74 | * @param {GET} sessionId ID of the session to route the command to | |
75 | */ | |
76 | ||
77 | 0 | Driver.addCommand({ |
78 | name: 'clearLocalStorage', | |
79 | url: '/session/:sessionId/local_storage', | |
80 | method: 'del' | |
81 | }); | |
82 | ||
83 | /** | |
84 | * Get the storage item for the given key | |
85 | * | |
86 | * @method getLocalStorageEntry | |
87 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/local_storage/key/:key | |
88 | * @param {GET} sessionId ID of the session to route the command to | |
89 | * @param {GET} key The key to get | |
90 | */ | |
91 | ||
92 | 0 | Driver.addCommand({ |
93 | name: 'getLocalStorageEntry', | |
94 | url: '/session/:sessionId/local_storage/key/:key', | |
95 | method: 'get' | |
96 | }); | |
97 | ||
98 | /** | |
99 | * Remove the storage item for the given key | |
100 | * | |
101 | * @method deleteLocalStorageEntry | |
102 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#DELETE_/session/:sessionId/local_storage/key/:key | |
103 | * @param {GET} sessionId ID of the session to route the command to | |
104 | * @param {GET} key The key to get | |
105 | */ | |
106 | ||
107 | 0 | Driver.addCommand({ |
108 | name: 'deleteLocalStorageEntry', | |
109 | url: '/session/:sessionId/local_storage/key/:key', | |
110 | method: 'del' | |
111 | }); | |
112 | ||
113 | /** | |
114 | * Get the number of items in the storage | |
115 | * | |
116 | * @method getLocalStorageSize | |
117 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/local_storage/size | |
118 | * @param {GET} sessionId ID of the session to route the command to | |
119 | */ | |
120 | ||
121 | 0 | Driver.addCommand({ |
122 | name: 'getLocalStorageSize', | |
123 | url: '/session/:sessionId/local_storage/size', | |
124 | method: 'get' | |
125 | }); | |
126 | ||
127 | /** | |
128 | * Get all keys of the browsers session storage | |
129 | * | |
130 | * @method getSessionStorage | |
131 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/session_storage | |
132 | * @param {GET} sessionId ID of the session to route the command to | |
133 | */ | |
134 | ||
135 | 0 | Driver.addCommand({ |
136 | name: 'getSessionStorage', | |
137 | url: '/session/:sessionId/session_storage', | |
138 | method: 'get' | |
139 | }); | |
140 | ||
141 | /** | |
142 | * Set the storage item for the given key | |
143 | * | |
144 | * @method setSessionStorage | |
145 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/session_storage | |
146 | * @param {GET} sessionId ID of the session to route the command to | |
147 | * @param {POST} key The key to set | |
148 | * @param {POST} value The value to set | |
149 | */ | |
150 | ||
151 | 0 | Driver.addCommand({ |
152 | name: 'setSessionStorage', | |
153 | url: '/session/:sessionId/session_storage', | |
154 | method: 'post', | |
155 | params: {key: 'key', value: 'value'} | |
156 | }); | |
157 | ||
158 | /** | |
159 | * Clears the complete session storage | |
160 | * | |
161 | * @method clearSessionStorage | |
162 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#DELETE_/session/:sessionId/session_storage | |
163 | * @param {GET} sessionId ID of the session to route the command to | |
164 | */ | |
165 | ||
166 | 0 | Driver.addCommand({ |
167 | name: 'clearSessionStorage', | |
168 | url: '/session/:sessionId/session_storage', | |
169 | method: 'del' | |
170 | }); | |
171 | ||
172 | /** | |
173 | * Get the storage item for the given key | |
174 | * | |
175 | * @method getSessionStorageEntry | |
176 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/session_storage/key/:key | |
177 | * @param {GET} sessionId ID of the session to route the command to | |
178 | * @param {GET} key The key to get | |
179 | */ | |
180 | ||
181 | 0 | Driver.addCommand({ |
182 | name: 'getSessionStorageEntry', | |
183 | url: '/session/:sessionId/session_storage/key/:key', | |
184 | method: 'get' | |
185 | }); | |
186 | ||
187 | /** | |
188 | * Remove the storage item for the given key | |
189 | * | |
190 | * @method deleteSessionStorageEntry | |
191 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#DELETE_/session/:sessionId/session_storage/key/:key | |
192 | * @param {GET} sessionId ID of the session to route the command to | |
193 | * @param {GET} key The key to get | |
194 | */ | |
195 | ||
196 | 0 | Driver.addCommand({ |
197 | name: 'deleteSessionStorageEntry', | |
198 | url: '/session/:sessionId/session_storage/key/:key', | |
199 | method: 'del' | |
200 | }); | |
201 | ||
202 | /** | |
203 | * Get the number of items in the storage | |
204 | * | |
205 | * @method getSessionStorageSize | |
206 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/session_storage/size | |
207 | * @param {GET} sessionId ID of the session to route the command to | |
208 | */ | |
209 | ||
210 | 0 | Driver.addCommand({ |
211 | name: 'getSessionStorageSize', | |
212 | url: '/session/:sessionId/session_storage/size', | |
213 | method: 'get' | |
214 | }); | |
215 | ||
216 | /** | |
217 | * Get the status of the html5 application cache. | |
218 | * | |
219 | * @method applicationCacheStatus | |
220 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/application_cache/status | |
221 | * @param {GET} sessionId ID of the session to route the command to | |
222 | */ | |
223 | ||
224 | 0 | Driver.addCommand({ |
225 | name: 'applicationCacheStatus', | |
226 | url: '/session/:sessionId/application_cache/status', | |
227 | method: 'get' | |
228 | }); | |
229 | ||
230 | }; | |
231 |
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 | * Timeout related WebDriver endpoints | |
29 | * see [JsonWireProtocol](https://code.google.com/p/selenium/wiki/JsonWireProtocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class Timeout | |
33 | * @namespace FirefoxDriver.Commands.WebDriver | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function (Driver) { |
37 | ||
38 | /** | |
39 | * Configure the amount of time that a particular type of operation can execute for before | |
40 | * they are aborted and a |Timeout| error is returned to the client. | |
41 | * | |
42 | * @method timeouts | |
43 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/timeouts | |
44 | * @param {GET} sessionId ID of the session to route the command to | |
45 | * @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 | |
46 | * @param {POST} ms The amount of time to wait, in milliseconds. This value has a lower bound of 0 | |
47 | */ | |
48 | ||
49 | 0 | Driver.addCommand({ |
50 | name: 'timeouts', | |
51 | url: '/session/:sessionId/timeouts', | |
52 | method: 'post', | |
53 | params: {type: 'type', timeout: 'ms'} | |
54 | }); | |
55 | ||
56 | /** | |
57 | * Set the amount of time the driver should wait when searching for elements. | |
58 | * When searching for a single element, the driver should poll the page until an element | |
59 | * is found or the timeout expires, whichever occurs first. When searching for multiple elements, | |
60 | * the driver should poll the page until at least one element is found or the timeout expires, | |
61 | * at which point it should return an empty list. | |
62 | * | |
63 | * @method implicitWait | |
64 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/timeouts/implicit_wait | |
65 | * @param {GET} sessionId ID of the session to route the command to | |
66 | * @param {POST} ms The amount of time to wait, in milliseconds. This value has a lower bound of 0 | |
67 | */ | |
68 | ||
69 | 0 | Driver.addCommand({ |
70 | name: 'implicitWait', | |
71 | url: '/session/:sessionId/timeouts/implicit_wait', | |
72 | method: 'post', | |
73 | params: {timeout: 'ms'} | |
74 | }); | |
75 | ||
76 | /** | |
77 | * Set the amount of time, in milliseconds, that asynchronous scripts executed by | |
78 | * /session/:sessionId/execute_async are permitted to run before they are aborted | |
79 | * and a |Timeout| error is returned to the client. | |
80 | * | |
81 | * @method asyncScript | |
82 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/timeouts/async_script | |
83 | * @param {GET} sessionId ID of the session to route the command to | |
84 | * @param {POST} ms The amount of time to wait, in milliseconds. This value has a lower bound of 0 | |
85 | */ | |
86 | ||
87 | 0 | Driver.addCommand({ |
88 | name: 'asyncScript', | |
89 | url: '/session/:sessionId/timeouts/async_script', | |
90 | method: 'post', | |
91 | params: {timeout: 'ms'} | |
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 | 1 | 'use strict'; |
26 | ||
27 | /** | |
28 | * URL related WebDriver endpoints | |
29 | * see [JsonWireProtocol](https://code.google.com/p/selenium/wiki/JsonWireProtocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class URL | |
33 | * @namespace FirefoxDriver.Commands.WebDriver | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function (Driver) { |
37 | ||
38 | /** | |
39 | * Navigate to a new URL | |
40 | * | |
41 | * @method open | |
42 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/url | |
43 | * @param {GET} sessionId ID of the session to route the command to | |
44 | * @param {POST} url The URL to navigate to. | |
45 | */ | |
46 | ||
47 | 0 | Driver.addCommand({ |
48 | name: 'open', | |
49 | url: '/session/:sessionId/url', | |
50 | method: 'post', | |
51 | params: {url: 'url'} | |
52 | }); | |
53 | ||
54 | /** | |
55 | * Retrieve the URL of the current page | |
56 | * | |
57 | * @method url | |
58 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/url | |
59 | * @param {GET} sessionId ID of the session to route the command to | |
60 | */ | |
61 | ||
62 | 0 | Driver.addCommand({ |
63 | name: 'url', | |
64 | url: '/session/:sessionId/url', | |
65 | method: 'get' | |
66 | }); | |
67 | ||
68 | /** | |
69 | * Navigate forwards in the browser history, if possible. | |
70 | * | |
71 | * @method forward | |
72 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/forward | |
73 | * @param {GET} sessionId ID of the session to route the command to | |
74 | */ | |
75 | ||
76 | 0 | Driver.addCommand({ |
77 | name: 'forward', | |
78 | url: '/session/:sessionId/forward', | |
79 | method: 'post', | |
80 | timeout: 1000 | |
81 | }); | |
82 | ||
83 | /** | |
84 | * Navigate backwards in the browser history, if possible | |
85 | * | |
86 | * @method back | |
87 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/back | |
88 | * @param {GET} sessionId ID of the session to route the command to | |
89 | */ | |
90 | ||
91 | 0 | Driver.addCommand({ |
92 | name: 'back', | |
93 | url: '/session/:sessionId/back', | |
94 | method: 'post', | |
95 | timeout: 1000 | |
96 | }); | |
97 | ||
98 | /** | |
99 | * Refresh the current page | |
100 | * | |
101 | * @method refresh | |
102 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/back | |
103 | * @param {GET} sessionId ID of the session to route the command to | |
104 | */ | |
105 | ||
106 | 0 | Driver.addCommand({ |
107 | name: 'refresh', | |
108 | url: '/session/:sessionId/refresh', | |
109 | method: 'post', | |
110 | timeout: 1000 | |
111 | }); | |
112 | ||
113 | }; | |
114 |
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 | * Window related WebDriver endpoints | |
29 | * see [JsonWireProtocol](https://code.google.com/p/selenium/wiki/JsonWireProtocol) | |
30 | * | |
31 | * @module FirefoxDriver | |
32 | * @class Window | |
33 | * @namespace FirefoxDriver.Commands.WebDriver | |
34 | */ | |
35 | ||
36 | 1 | module.exports = function (Driver) { |
37 | ||
38 | /** | |
39 | * Retrieve the current window handle. | |
40 | * | |
41 | * @method windowHandle | |
42 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/window_handle | |
43 | * @param {GET} sessionId ID of the session to route the command to | |
44 | */ | |
45 | ||
46 | 0 | Driver.addCommand({ |
47 | name: 'windowHandle', | |
48 | url: '/session/:sessionId/window_handle', | |
49 | method: 'get' | |
50 | }); | |
51 | ||
52 | /** | |
53 | * Retrieve the list of all window handles available to the session. | |
54 | * | |
55 | * @method windowHandles | |
56 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/window_handles | |
57 | * @param {GET} sessionId ID of the session to route the command to | |
58 | */ | |
59 | ||
60 | 0 | Driver.addCommand({ |
61 | name: 'windowHandles', | |
62 | url: '/session/:sessionId/window_handles', | |
63 | method: 'get' | |
64 | }); | |
65 | ||
66 | /** | |
67 | * Change focus to another window. | |
68 | * The window to change focus to may be specified by its server assigned window handle, or by the value of its name attribute. | |
69 | * | |
70 | * @method changeWindow | |
71 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/window | |
72 | * @param {GET} sessionId ID of the session to route the command to | |
73 | * @param {POST} name Name of the window to switch to | |
74 | */ | |
75 | ||
76 | 0 | Driver.addCommand({ |
77 | name: 'changeWindow', | |
78 | url: '/session/:sessionId/window', | |
79 | method: 'post', | |
80 | params: {name: 'name'} | |
81 | }); | |
82 | ||
83 | /** | |
84 | * Close the current window. | |
85 | * | |
86 | * @method closeWindow | |
87 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#DELETE_/session/:sessionId/window | |
88 | * @param {GET} sessionId ID of the session to route the command to | |
89 | */ | |
90 | ||
91 | 0 | Driver.addCommand({ |
92 | name: 'closeWindow', | |
93 | url: '/session/:sessionId/window', | |
94 | method: 'del' | |
95 | }); | |
96 | ||
97 | /** | |
98 | * Change the size of the specified window. | |
99 | * If the :windowHandle URL parameter is "current", the currently active window will be resized. | |
100 | * | |
101 | * @method windowSize | |
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 | */ | |
106 | ||
107 | 0 | Driver.addCommand({ |
108 | name: 'windowSize', | |
109 | url: '/session/:sessionId/window/:windowHandle/size', | |
110 | method: 'post', | |
111 | params: {width: 'width', height: 'height'}, | |
112 | onRequest: function (req, res) { | |
113 | // load the marionette connection id & then request the session id | |
114 | 0 | this.events.emit('marionette:cmd:windowSize', {'sessionId': req.params.sessionId, 'value': 'window.resizeTo("' + req.body.height + '", "' + req.body.width + '")' }); |
115 | 0 | this.events.on('marionette:cmd:windowSize:response', function () { |
116 | 0 | var answer = { |
117 | sessionId: req.params.sessionId, | |
118 | status: 0, | |
119 | value: true | |
120 | }; | |
121 | ||
122 | 0 | res.status(200); |
123 | 0 | res.send(JSON.stringify(answer)); |
124 | }.bind(this)); | |
125 | } | |
126 | }); | |
127 | ||
128 | /** | |
129 | * Get the size of the specified window. | |
130 | * If the :windowHandle URL parameter is "current", the size of the currently active window will be returned. | |
131 | * | |
132 | * @method getWindowSize | |
133 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/window/:windowHandle/size | |
134 | * @param {GET} sessionId ID of the session to route the command to | |
135 | * @param {GET} windowHandle ID of the window to route the command to | |
136 | */ | |
137 | ||
138 | 0 | Driver.addCommand({ |
139 | name: 'getWindowSize', | |
140 | url: '/session/:sessionId/window/:windowHandle/size', | |
141 | method: 'get' | |
142 | }); | |
143 | ||
144 | ||
145 | /** | |
146 | * Change the position of the specified window. | |
147 | * If the :windowHandle URL parameter is "current", the currently active window will be moved. | |
148 | * | |
149 | * @method windowPosition | |
150 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/window/:windowHandle/position | |
151 | * @param {GET} sessionId ID of the session to route the command to | |
152 | * @param {GET} windowHandle ID of the window to route the command to | |
153 | */ | |
154 | ||
155 | 0 | Driver.addCommand({ |
156 | name: 'windowPosition', | |
157 | url: '/session/:sessionId/window/:windowHandle/position', | |
158 | method: 'post', | |
159 | params: {x: 'x', y: 'y'} | |
160 | }); | |
161 | ||
162 | /** | |
163 | * Get the position of the specified window. | |
164 | * If the :windowHandle URL parameter is "current", the position of the currently active window will be returned. | |
165 | * | |
166 | * @method getWindowPosition | |
167 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/window/:windowHandle/position | |
168 | * @param {GET} sessionId ID of the session to route the command to | |
169 | * @param {GET} windowHandle ID of the window to route the command to | |
170 | */ | |
171 | ||
172 | 0 | Driver.addCommand({ |
173 | name: 'getWindowPosition', | |
174 | url: '/session/:sessionId/window/:windowHandle/position', | |
175 | method: 'get' | |
176 | }); | |
177 | ||
178 | /** | |
179 | * Maximize the specified window if not already maximized. | |
180 | * If the :windowHandle URL parameter is "current", the currently active window will be maximized. | |
181 | * | |
182 | * @method windowMaximize | |
183 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/window/:windowHandle/position | |
184 | * @param {GET} sessionId ID of the session to route the command to | |
185 | * @param {GET} windowHandle ID of the window to route the command to | |
186 | */ | |
187 | ||
188 | 0 | Driver.addCommand({ |
189 | name: 'windowMaximize', | |
190 | url: '/session/:sessionId/window/:windowHandle/maximize', | |
191 | method: 'get' | |
192 | }); | |
193 | ||
194 | /** | |
195 | * Get the current browser orientation. | |
196 | * The server should return a valid orientation value {LANDSCAPE|PORTRAIT}. | |
197 | * | |
198 | * @method getOrientation | |
199 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/orientation | |
200 | * @param {GET} sessionId ID of the session to route the command to | |
201 | */ | |
202 | ||
203 | 0 | Driver.addCommand({ |
204 | name: 'getOrientation', | |
205 | url: '/session/:sessionId/orientation', | |
206 | method: 'get' | |
207 | }); | |
208 | ||
209 | /** | |
210 | * Set the browser orientation. | |
211 | * Must be one of the two values {LANDSCAPE|PORTRAIT}. | |
212 | * | |
213 | * @method orientation | |
214 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/orientation | |
215 | * @param {GET} sessionId ID of the session to route the command to | |
216 | * @param {POST} orientation The new browser orientation {LANDSCAPE|PORTRAIT}. | |
217 | */ | |
218 | ||
219 | 0 | Driver.addCommand({ |
220 | name: 'orientation', | |
221 | url: '/session/:sessionId/orientation', | |
222 | method: 'post', | |
223 | params: {orientation: 'orientation'} | |
224 | }); | |
225 | ||
226 | /** | |
227 | * Gets the text of the currently displayed JavaScript alert(), confirm(), or prompt() dialog. | |
228 | * | |
229 | * @method dialogText | |
230 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/alert_text | |
231 | * @param {GET} sessionId ID of the session to route the command to | |
232 | */ | |
233 | ||
234 | 0 | Driver.addCommand({ |
235 | name: 'dialogText', | |
236 | url: '/session/:sessionId/alert_text', | |
237 | method: 'get' | |
238 | }); | |
239 | ||
240 | /** | |
241 | * Sends keystrokes to a JavaScript prompt() dialog. | |
242 | * | |
243 | * @method alertText | |
244 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/alert_text | |
245 | * @param {GET} sessionId ID of the session to route the command to | |
246 | * @param {POST} text Keystrokes to send to the prompt() dialog. | |
247 | */ | |
248 | ||
249 | 0 | Driver.addCommand({ |
250 | name: 'setDialogText', | |
251 | url: '/session/:sessionId/alert_text', | |
252 | method: 'post', | |
253 | params: {text: 'text'} | |
254 | }); | |
255 | ||
256 | /** | |
257 | * Accepts the currently displayed alert dialog. | |
258 | * Usually, this is equivalent to clicking on the 'OK' button in the dialog. | |
259 | * | |
260 | * @method acceptDialog | |
261 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/accept_alert | |
262 | * @param {GET} sessionId ID of the session to route the command to | |
263 | */ | |
264 | ||
265 | 0 | Driver.addCommand({ |
266 | name: 'acceptDialog', | |
267 | url: '/session/:sessionId/accept_alert', | |
268 | method: 'post' | |
269 | }); | |
270 | ||
271 | /** | |
272 | * Dismisses the currently displayed alert dialog. | |
273 | * For confirm() and prompt() dialogs, this is equivalent to clicking the 'Cancel' button. | |
274 | * For alert() dialogs, this is equivalent to clicking the 'OK' button. | |
275 | * | |
276 | * @method dismissDialog | |
277 | * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/dismiss_alert | |
278 | * @param {GET} sessionId ID of the session to route the command to | |
279 | */ | |
280 | ||
281 | 0 | Driver.addCommand({ |
282 | name: 'dismissDialog', | |
283 | url: '/session/:sessionId/dismiss_alert', | |
284 | method: 'post' | |
285 | }); | |
286 | ||
287 | }; | |
288 |
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 fs = require('fs'); |
29 | 1 | var net = require('net'); |
30 | 1 | var Q = require('q'); |
31 | ||
32 | /** | |
33 | * Firefox Autotest (Marionette) | |
34 | * connection handler & request executor | |
35 | * | |
36 | * @module FirefoxDriver | |
37 | * @class Marionette | |
38 | * @namespace FirefoxDriver | |
39 | */ | |
40 | ||
41 | /** | |
42 | * Configures the marionette socket | |
43 | * Prepares the object properties | |
44 | * Loads the marionette commands | |
45 | * | |
46 | * @constructor | |
47 | * @param {EventEmitter} events | |
48 | */ | |
49 | ||
50 | 1 | var Marionette = function (events) { |
51 | // configure the marionette socket | |
52 | 0 | this.socket = new net.Socket(); |
53 | 0 | this.socket.on('error', this._onError.bind(this)); |
54 | 0 | this.socket.on('data', this._onData.bind(this)); |
55 | ||
56 | // configure marionette session container | |
57 | 0 | this._marionetteID = null; |
58 | ||
59 | // store events instance | |
60 | 0 | this.events = events; |
61 | ||
62 | // register marionette id setter | |
63 | 0 | this.events.on('marionette:setMarionetteID', function (id) { |
64 | 0 | this._marionetteID = id; |
65 | }.bind(this)); | |
66 | ||
67 | // prepare the commands property | |
68 | 0 | this.commands = {}; |
69 | ||
70 | // prepare the last send command property | |
71 | 0 | this._lastCommand = null; |
72 | ||
73 | // prepare the last message length property | |
74 | 0 | this._lastMessageLength = null; |
75 | ||
76 | // load the commands | |
77 | 0 | this._loadCommands(); |
78 | }; | |
79 | ||
80 | /** | |
81 | * Opens the marionette socket | |
82 | * | |
83 | * @method connect | |
84 | * @param {integer} marionettePort | |
85 | * @return {Q.promise} promise | |
86 | * @public | |
87 | */ | |
88 | ||
89 | 1 | Marionette.prototype.connect = function (marionettePort) { |
90 | 0 | var deferred = Q.defer(); |
91 | 0 | this.socket.on('connect', deferred.resolve); |
92 | 0 | this.socket.connect(marionettePort); |
93 | 0 | return deferred.promise; |
94 | }; | |
95 | ||
96 | /** | |
97 | * Closes the marionette socket & cleans up | |
98 | * | |
99 | * @method kill | |
100 | * @return {Q.promise} promise | |
101 | * @public | |
102 | */ | |
103 | ||
104 | 1 | Marionette.prototype.kill = function () { |
105 | 0 | var deferred = Q.defer(); |
106 | 0 | this.socket.on('end', deferred.makeNodeResolver()); |
107 | 0 | this.socket.end(); |
108 | 0 | return deferred.promise; |
109 | }; | |
110 | ||
111 | /** | |
112 | * Generates a function & an event listener for every marionette command | |
113 | * | |
114 | * @method addCommand | |
115 | * @param {object} command | |
116 | * @return {object} command | |
117 | * @public | |
118 | */ | |
119 | ||
120 | 1 | Marionette.prototype.addCommand = function (command) { |
121 | // generate the command function | |
122 | 0 | this.commands[command.name] = function (params) { |
123 | 0 | var req = {}; |
124 | 0 | var deferred = Q.defer(); |
125 | ||
126 | 0 | deferred.promise.then(function (data) { |
127 | 0 | this.events.emit('marionette:cmd:' + command.name + ':response', JSON.stringify(data)); |
128 | }.bind(this)); | |
129 | ||
130 | // parse the command skeleton & create a message with values | |
131 | 0 | Object.keys(command.request).forEach(function (key){ |
132 | // cookie related hack | |
133 | 0 | if (command.name === 'cookies' && this._parseRequestKey(command.request[key], params) === '') { |
134 | } else { | |
135 | 0 | req[key] = this._parseRequestKey(command.request[key], params); |
136 | } | |
137 | }.bind(this)); | |
138 | ||
139 | // issue the command | |
140 | 0 | this._sendCommand(req, deferred); |
141 | }.bind(this); | |
142 | ||
143 | // generate event listener for every marionette command | |
144 | 0 | this.events.on('marionette:cmd:' + command.name, this.commands[command.name].bind(this)); |
145 | 0 | return command; |
146 | }; | |
147 | ||
148 | /** | |
149 | * Loads the marionette commands from the commands library | |
150 | * | |
151 | * @method _loadCommands | |
152 | * @chainable | |
153 | * @private | |
154 | */ | |
155 | ||
156 | 1 | Marionette.prototype._loadCommands = function () { |
157 | 0 | var dir = __dirname + '/commands/marionette/'; |
158 | 0 | fs.readdirSync(dir).forEach(function (file) { |
159 | 0 | require(dir + file)(this); |
160 | }.bind(this)); | |
161 | 0 | return this; |
162 | }; | |
163 | ||
164 | /** | |
165 | * Templating function that replaces placeholders in commands | |
166 | * with their actual values | |
167 | * | |
168 | * @method _parseRequestKey | |
169 | * @param {string} placeholder | |
170 | * @param {object} params | |
171 | * @return {string} content | |
172 | * @private | |
173 | */ | |
174 | ||
175 | 1 | Marionette.prototype._parseRequestKey = function (placeholder, params) { |
176 | 0 | if (typeof placeholder !== 'object' && placeholder[0] !== ':') { |
177 | 0 | return placeholder; |
178 | } | |
179 | ||
180 | // check the params | |
181 | 0 | if (!params) { |
182 | 0 | params = {}; |
183 | } | |
184 | ||
185 | // add the marionetteID to the params | |
186 | 0 | if (typeof placeholder !== 'object') { |
187 | 0 | params.marionetteId = this._marionetteID; |
188 | } | |
189 | ||
190 | 0 | var content = ''; |
191 | 0 | if (typeof placeholder !== 'object') { |
192 | 0 | Object.keys(params).forEach(function (key){ |
193 | 0 | if (key === placeholder.substr(1)) { |
194 | 0 | content = params[key]; |
195 | } | |
196 | }.bind(this)); | |
197 | } | |
198 | ||
199 | // check if we have a params object (and replace also there) | |
200 | 0 | if (typeof placeholder === 'object') { |
201 | 0 | content = {}; |
202 | ||
203 | 0 | Object.keys(params).forEach(function (key) { |
204 | 0 | Object.keys(placeholder).forEach(function (name) { |
205 | 0 | if (placeholder[name] && placeholder[name].substring(1) === key) { |
206 | 0 | content[name] = params[key]; |
207 | } | |
208 | }.bind(this)); | |
209 | }.bind(this)); | |
210 | ||
211 | 0 | Object.keys(placeholder).forEach(function (name) { |
212 | 0 | if (placeholder[name].substr(0, 1) !== ':') { |
213 | 0 | content[name] = placeholder[name]; |
214 | } | |
215 | }.bind(this)); | |
216 | } | |
217 | ||
218 | 0 | return content; |
219 | }; | |
220 | ||
221 | /** | |
222 | * Will be called if a socket error occurs | |
223 | * | |
224 | * @method _onError | |
225 | * @param {buffer} err | |
226 | * @chainable | |
227 | * @private | |
228 | */ | |
229 | ||
230 | 1 | Marionette.prototype._onError = function (err) { |
231 | // TODO: Use the super not yet implemented dalek error handler | |
232 | 0 | console.log('ERR', String(err)); |
233 | 0 | process.exit(); |
234 | 0 | return this; |
235 | }; | |
236 | ||
237 | /** | |
238 | * Handles the incoming data from the marionette sockets | |
239 | * | |
240 | * @method _onData | |
241 | * @param {buffer} data | |
242 | * @chainable | |
243 | * @private | |
244 | */ | |
245 | ||
246 | 1 | Marionette.prototype._onData = function (data) { |
247 | 0 | var def = Q.defer(); |
248 | 0 | var raw = String(data); |
249 | // extract the header out of the raw message | |
250 | 0 | var colon = raw.indexOf(':'); |
251 | 0 | var length = raw.substr(0, colon); |
252 | 0 | var msg = raw.substring(colon + 1); |
253 | ||
254 | // check if this is incoming data is a sibling | |
255 | // to a previous received message | |
256 | 0 | if (isNaN(parseInt(length, 10))) { |
257 | 0 | length = this._lastResponseLength; |
258 | } | |
259 | ||
260 | // store message data | |
261 | 0 | this._lastResponseLength = length; |
262 | 0 | this._lastResponse += msg; |
263 | 0 | this._lastRawResponse += raw; |
264 | ||
265 | // check if the message is complete | |
266 | 0 | if((this._lastResponse.length + 1) >= parseInt(length, 10)) { |
267 | // resolve the message | |
268 | 0 | def.resolve(this._lastRawResponse); |
269 | ||
270 | // reset our message storage | |
271 | 0 | this._lastRawResponse = ''; |
272 | 0 | this._lastResponse = ''; |
273 | 0 | this._lastResponseLength = null; |
274 | } | |
275 | ||
276 | // release the message when it is completely received | |
277 | 0 | Q.when(def.promise).then(function(data) { |
278 | // parse the message & call the resolving function | |
279 | 0 | var parsedMessage = this._parseMessage(data); |
280 | // avoid resolving the initial handshake command | |
281 | 0 | if (!parsedMessage.applicationType) { |
282 | 0 | this._lastCommand.resolve(parsedMessage); |
283 | } | |
284 | ||
285 | }.bind(this)); | |
286 | ||
287 | 0 | return this; |
288 | }; | |
289 | ||
290 | ||
291 | /** | |
292 | * Parses a marionette response message | |
293 | * | |
294 | * @method _parseMessage | |
295 | * @param {buffer} data | |
296 | * @return {object} message | |
297 | * @private | |
298 | */ | |
299 | ||
300 | 1 | Marionette.prototype._parseMessage = function (data) { |
301 | 0 | var raw = String(data); |
302 | 0 | var colon = raw.indexOf(':'); |
303 | 0 | var message = JSON.parse(raw.substring(colon + 1)); |
304 | 0 | return message; |
305 | }; | |
306 | ||
307 | /** | |
308 | * Issues a command to the marionette server | |
309 | * Generates a reference to the last called command, | |
310 | * so that we are able to call the right receiver function for | |
311 | * the response from marionette | |
312 | * | |
313 | * @method _sendCommand | |
314 | * @param {object} command | |
315 | * @param {Q.promise} deferred | |
316 | * @chainable | |
317 | * @private | |
318 | */ | |
319 | ||
320 | 1 | Marionette.prototype._sendCommand = function (command, deferred) { |
321 | // serialize message | |
322 | 0 | var commandSerialized = JSON.stringify(command); |
323 | 0 | var msg = commandSerialized.length + ':' + commandSerialized; |
324 | // reference promise | |
325 | 0 | this._lastCommand = deferred; |
326 | // send command | |
327 | 0 | this.socket.write(msg); |
328 | ||
329 | 0 | return this; |
330 | }; | |
331 | ||
332 | 1 | module.exports = Marionette; |
333 |
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 fs = require('fs'); |
29 | 1 | var Q = require('q'); |
30 | 1 | var express = require('express'); |
31 | 1 | var connect = require('connect'); |
32 | ||
33 | /** | |
34 | * Firefox Autotest (Marionette) | |
35 | * WebDriver handler & request executor | |
36 | * | |
37 | * @module FirefoxDriver | |
38 | * @class WebDriverServer | |
39 | * @namespace FirefoxDriver | |
40 | */ | |
41 | ||
42 | /** | |
43 | * Configures the express server | |
44 | * Prepares the object properties | |
45 | * Loads the webdriver commands | |
46 | * | |
47 | * @constructor | |
48 | * @param {EventEmitter} events | |
49 | */ | |
50 | ||
51 | 1 | var WebDriverServer = function (events) { |
52 | // store events | |
53 | 0 | this.events = events; |
54 | ||
55 | // placeholder for the webdriver server port & host | |
56 | 0 | this.port = null; |
57 | 0 | this.host = null; |
58 | ||
59 | // configure express | |
60 | 0 | this.app = express(); |
61 | ||
62 | 0 | this.app.use(connect.json()); |
63 | 0 | this.app.use(connect.urlencoded()); |
64 | ||
65 | // load the commands | |
66 | 0 | this._loadCommands(); |
67 | }; | |
68 | ||
69 | /** | |
70 | * Opens the WebDriverServer port | |
71 | * | |
72 | * @method connect | |
73 | * @param {integer} webdriverPort | |
74 | * @return {Q.promise} promise | |
75 | * @public | |
76 | */ | |
77 | ||
78 | 1 | WebDriverServer.prototype.connect = function (webdriverPort, webdriverHost) { |
79 | 0 | var deferred = Q.defer(); |
80 | // store host & port | |
81 | 0 | this.port = webdriverPort; |
82 | 0 | this.host = webdriverHost; |
83 | // start the webdriver server | |
84 | 0 | this.listener = this.app.listen(webdriverPort, deferred.resolve); |
85 | 0 | return deferred.promise; |
86 | }; | |
87 | ||
88 | /** | |
89 | * Closes the webdriver server port & cleans up | |
90 | * | |
91 | * @method kill | |
92 | * @return {Q.promise} promise | |
93 | * @public | |
94 | */ | |
95 | ||
96 | 1 | WebDriverServer.prototype.kill = function () { |
97 | 0 | var deferred = Q.defer(); |
98 | 0 | this.listener.close(deferred.resolve); |
99 | 0 | return deferred.promise; |
100 | }; | |
101 | ||
102 | /** | |
103 | * Generates a function for every webdriver command | |
104 | * and an express route endpoint | |
105 | * | |
106 | * @method addCommand | |
107 | * @param {object} command | |
108 | * @return {object} command | |
109 | * @public | |
110 | */ | |
111 | ||
112 | 1 | WebDriverServer.prototype.addCommand = function (command) { |
113 | // bind the command callback (on request) | |
114 | 0 | var cb = command.onRequest ? command.onRequest.bind(this) : this._onRequest.bind(this, command); |
115 | // register the REST endpoint | |
116 | 0 | this.app[command.method](command.url, cb); |
117 | 0 | return command; |
118 | }; | |
119 | ||
120 | /** | |
121 | * Loads the webdriver commands (aka. REST endpoints) from the commands library | |
122 | * | |
123 | * @method _loadCommands | |
124 | * @chainable | |
125 | * @private | |
126 | */ | |
127 | ||
128 | 1 | WebDriverServer.prototype._loadCommands = function () { |
129 | 0 | var dir = __dirname + '/commands/webdriver/'; |
130 | 0 | fs.readdirSync(dir).forEach(function (file) { |
131 | 0 | require(dir + file)(this); |
132 | }.bind(this)); | |
133 | 0 | return this; |
134 | }; | |
135 | ||
136 | /** | |
137 | * Default webdriver request handler, | |
138 | * will be used if no `onRequest` method is given in the | |
139 | * webdriver command | |
140 | * | |
141 | * @method _onRequest | |
142 | * @param {object} command | |
143 | * @param {object} req | |
144 | * @param {object} res | |
145 | * @chainable | |
146 | * @private | |
147 | */ | |
148 | ||
149 | 1 | WebDriverServer.prototype._onRequest = function (command, req, res) { |
150 | // extract the request paramters | |
151 | 0 | var parameters = {}; |
152 | 0 | Object.keys(req.params).forEach(function (key) { |
153 | 0 | parameters[key] = req.params[key]; |
154 | }); | |
155 | ||
156 | // add paramters extracted from the post body if necessary | |
157 | 0 | if (command.params) { |
158 | 0 | Object.keys(command.params).forEach(function (key) { |
159 | 0 | parameters[key] = req.body[command.params[key]]; |
160 | }); | |
161 | } | |
162 | ||
163 | // trigger the marionette command | |
164 | 0 | this.events.emit('marionette:cmd:' + command.name, parameters); |
165 | ||
166 | // generate & send the webdriver response when the command has been executed by marionette | |
167 | 0 | this.events.on('marionette:cmd:' + command.name + ':response', function (data) { |
168 | 0 | var parsedData = {}; |
169 | ||
170 | 0 | try { |
171 | 0 | parsedData = JSON.parse(data); |
172 | } catch (e) { | |
173 | 0 | parsedData = data; |
174 | } | |
175 | ||
176 | 0 | data = parsedData; |
177 | 0 | var answer = { sessionId: parameters.sessionId, status: 0}; |
178 | ||
179 | // check if we need to send a value with the response | |
180 | 0 | if (data.value || data.value === false) { |
181 | 0 | answer.value = data.value; |
182 | } | |
183 | ||
184 | 0 | res.status(200); |
185 | 0 | res.send(JSON.stringify(answer)); |
186 | ||
187 | }.bind(this)); | |
188 | ||
189 | 0 | return this; |
190 | }; | |
191 | ||
192 | 1 | module.exports = WebDriverServer; |
193 |