Coverage

17%
545
95
450

/home/ubuntu/src/github.com/dalekjs/dalek-browser-firefox/index.js

10%
146
16
130
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27// ext. libs
281var Q = require('q');
291var fs = require('fs');
301var path = require('path');
311var rimraf = require('rimraf');
321var which = require('which').sync;
331var portscanner = require('portscanner');
341var spawn = require('child_process').spawn;
351var Events = require('events').EventEmitter;
36
37// int. libs
381var Marionette = require('./lib/marionette');
391var 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
1431var 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 () {
3471 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 () {
3580 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 () {
3691 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 () {
3801 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) {
3960 var deferred = Q.defer();
397
398 // init the webdriver server,
399 // marionette client, event glue
400 // and configuration settings
4010 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
4090 var browsers = this.config.get('browsers');
4100 if (browsers && Array.isArray(browsers)) {
4110 browsers.forEach(this._checkUserDefinedPorts.bind(this));
412 }
413
414 // check the path of the browser binary
4150 Q.when(this.findBrowserBinary(configuration))
416 .then(this._afterBinaryFound.bind(this, configuration, deferred));
417
4180 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 () {
4300 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
4370 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) {
4490 var deferred = Q.defer();
450
451 // check if the user has set a custom binary
4520 if (options && options.binary) {
4530 this._checkUserSetBinary(options.binary, deferred);
4540 return deferred.promise;
455 }
456
457 // get the defaukt binary for this OS
4580 var defaultBinary = this._getDefaultBinary();
459
460 // check if the binary exists
4610 if (fs.existsSync(defaultBinary)) {
4620 this.binary = defaultBinary;
4630 deferred.resolve(defaultBinary);
464 } else {
4650 var msg = 'dalek-driver-firefox: Binary not found: ' + defaultBinary;
4660 this.reporterEvents.emit('error', msg);
4670 deferred.reject({error: true, msg: msg});
468 }
469
4700 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
4860 this.longName = this._modifyVerboseBrowserName(configuration);
487
488 // check if we are driving a desktop browser
489 // when, create a profile, else, not
4900 if (configuration.type !== 'os') {
4910 Q.when(this._createProfile())
492 .then(this._afterDesktopBinaryFound.bind(this, deferred, configuration));
493 } else {
4940 this._startBrowser(null, 'os', deferred);
495 }
496
4970 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) {
5100 if (configuration.type && this.browserTypes[configuration.type]) {
5110 return this.browserTypes[configuration.type].name + ' (' + this.longName + ')';
512 } else {
5130 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) {
5280 this._startBrowser(this.profile.path, this.profile.name, deferred, configuration);
5290 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
5420 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
5460 if (this.profile && this.profile.path) {
5470 rimraf.sync(this.profile.path);
548 }
549
5500 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
5640 this.config = opts.config;
565
566 // glue events
5670 this.events = opts.events;
5680 this.events.setMaxListeners(0);
5690 this.reporterEvents = opts.reporterEvents;
570
571 // setup Marionette client & Webdriver server
5720 this.marionette = new Marionette(this.events);
5730 this.webDriverServer = new WebDriverServer(this.events);
574
5750 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 () {
5870 var platform = process.platform;
588
589 // check default binary for linuy
5900 if (platform !== 'darwin' && platform !== 'win32' && this.defaultBinaries[platform]) {
5910 return which(this.defaultBinaries.linux);
592 }
593
594 // check to see if we are on Windows x64
5950 if (platform === 'win32' && process.arch === 'x64') {
5960 platform = 'win64';
597 }
598
5990 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) {
6160 var df = Q.defer();
6170 var args = [];
618
619 // set args based on environment
6200 if (profileName !== 'os') {
6210 args = ['-marionette', '-turbo', '-profile', profilePath, '-no-remote', '-url', 'about:blank'];
622 }
623
624 // start the browser
6250 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
6290 if (process.platform === 'win32' || (configuration && !configuration.type)) {
6300 this.interval = setInterval(this._scanMarionettePort.bind(this, df), 50);
631 } else {
6320 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
6370 df.promise.then(this._resolvePort.bind(this, deferred, profileName));
6380 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) {
6510 portscanner.checkPortStatus(this.getMarionettePort(), this.getHost(), this._startByInterval.bind(this, df));
6520 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) {
6680 if (status === 'open') {
6690 clearInterval(this.interval);
6700 df.resolve();
671 }
672
6730 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
6870 if (browser.firefox && browser.firefox.port) {
6880 this.port = parseInt(browser.firefox.port, 10);
6890 this.maxPort = this.port + 90;
6900 this.reporterEvents.emit('report:log:system', 'dalek-browser-firefox: Switching to user defined port: ' + this.port);
691 }
692
693 // check for a port range
6940 if (browser.firefox && browser.firefox.portRange && browser.firefox.portRange.length === 2) {
6950 this.port = parseInt(browser.firefox.portRange[0], 10);
6960 this.maxPort = parseInt(browser.firefox.portRange[1], 10);
6970 this.reporterEvents.emit('report:log:system', 'dalek-browser-firefox: Switching to user defined port(s): ' + this.port + ' -> ' + this.maxPort);
698 }
699
7000 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
7150 portscanner.findAPortNotInUse(
716 this.getPort(),
717 this.getMaxPort(),
718 this.getHost(),
719 this._afterPortResolved.bind(this, deferred, profileName)
720 );
721
7220 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
7390 if (error !== null && error.code !== 'ECONNREFUSED') {
7400 this.reporterEvents.emit('error', 'dalek-browser-firefox: Error starting WebDriverServer, port ' + port + ' in use');
7410 deferred.reject(error);
7420 process.exit();
743 }
744
745 // check if the port was blocked & if we need to switch to another port
7460 if (this.port !== port) {
7470 this.reporterEvents.emit('report:log:system', 'dalek-browser-firefox: Switching to port: ' + port);
7480 this.port = port;
749 }
750
751 // kickstart marionette client & webdriver server
7520 Q.all([
753 this.webDriverServer.connect(this.getPort(), this.getHost()),
754 this.marionette.connect(this.getMarionettePort())
755 ]).then(this._afterConnectionHasBeenEstablished.bind(this, profileName, deferred));
7560 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
7750 if (profileName === 'os') {
7760 setTimeout(deferred.resolve, 1000);
777 } else {
7780 deferred.resolve();
779 }
780
7810 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) {
7950 if (this._browserIsReady(data)) {
7960 deferred.resolve();
797 }
7980 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
8120 data = data+'';
813 // check for the ready signal on desktop firefox
8140 var desktopReady = data.search('DOMWINDOW == 12') !== -1;
815 // check for the ready signal of the firefoxos emulator
8160 var b2gReady = data.search('BrowserElementChildPreload.js loaded') !== -1;
8170 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 () {
8300 var deferred = Q.defer();
8310 var profileName = 'dalekjs-' + Math.random().toString(16).slice(2);
8320 this._createUserPreferences(deferred, profileName);
833
8340 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
8490 var prefs = 'user_pref("browser.shell.checkDefaultBrowser", false);\n';
8500 prefs += 'user_pref("marionette.contentListener", false);\n';
8510 prefs += 'user_pref("marionette.defaultPrefs.enabled", true);\n';
8520 prefs += 'user_pref("browser.shell.checkDefaultBrowser", false);\n';
8530 prefs += 'user_pref("browser.sessionstore.resume_from_crash", false);\n';
8540 prefs += 'user_pref("browser.bookmarks.restore_default_bookmarks", false);\n';
8550 prefs += 'user_pref("marionette.defaultPrefs.port", "' + this.getMarionettePort() + '");\n';
856
857 // store the user preferences
8580 this.profile = {};
8590 this.profile.path = path.join(process.cwd(), 'temp');
8600 this.profile.name = profileName;
861
862 // check if the temp dir exists, else create
8630 if (!fs.existsSync(this.profile.path)) {
8640 fs.mkdirSync(this.profile.path);
865 }
866
867 // create the preference file
8680 fs.writeFile(path.join(this.profile.path, 'prefs.js'), prefs, this._afterCreatingUserPreferences.bind(this, deferred));
8690 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
8850 if (err !== null) {
8860 this.reporterEvents.emit('error', 'dalek-browser-firefox: Error creating profile');
8870 deferred.reject(err);
8880 process.exit();
889 }
890
8910 deferred.resolve();
8920 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
9080 if (process.platform === 'darwin' && userPath.trim()[0] === '~') {
9090 userPath = userPath.replace('~', process.env.HOME);
910 }
911
912 // check if the binary exists
9130 if (fs.existsSync(userPath)) {
9140 this.binary = userPath;
9150 deferred.resolve(userPath);
916 } else {
9170 var msg = 'dalek-driver-firefox: Binary not found: ' + userPath;
9180 this.reporterEvents.emit('error', msg);
9190 process.exit(); // MAYBE switch to Daleks 'killAll' Event
9200 deferred.reject({error: true, msg: msg});
921 }
922
9230 return this;
924 }
925};
926
9271module.exports = FirefoxDriver;
928

/home/ubuntu/src/github.com/dalekjs/dalek-browser-firefox/lib/commands/marionette/cookie.js

33%
6
2
4
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27/**
28 * 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
361module.exports = function (Marionette) {
37
38 /**
39 * Retrieve all cookies visible to the current page.
40 *
41 * @method getCookies
42 */
43
440 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
590 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
750 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
940 Marionette.addCommand({
95 name: 'cookies',
96 request: {
97 to: ':marionetteId',
98 session: ':sessionId',
99 cookie: ':cookie',
100 name: 'addCookie'
101 }
102 });
103
104};
105

/home/ubuntu/src/github.com/dalekjs/dalek-browser-firefox/lib/commands/marionette/element.js

13%
15
2
13
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27/**
28 * 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
361module.exports = function (Marionette) {
37
38 /**
39 * Selects an element
40 *
41 * @method element
42 */
43
440 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
640 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
840 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
1010 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
1180 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
1350 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
1540 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
1740 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
1930 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
2130 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
2320 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
2520 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
2710 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

/home/ubuntu/src/github.com/dalekjs/dalek-browser-firefox/lib/commands/marionette/execute.js

50%
4
2
2
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'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
361module.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
490 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
790 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

/home/ubuntu/src/github.com/dalekjs/dalek-browser-firefox/lib/commands/marionette/frame.js

66%
3
2
1
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'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
361module.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
450 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

/home/ubuntu/src/github.com/dalekjs/dalek-browser-firefox/lib/commands/marionette/ime.js

66%
3
2
1
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'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
361module.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
490 Marionette.addCommand({
50 name: 'status',
51 request: {
52 to: ':marionetteId',
53 name: 'getStatus'
54 }
55 });
56
57};
58

/home/ubuntu/src/github.com/dalekjs/dalek-browser-firefox/lib/commands/marionette/interaction.js

100%
2
2
0
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27/**
28 * 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
361module.exports = function () {
37
38};
39

/home/ubuntu/src/github.com/dalekjs/dalek-browser-firefox/lib/commands/marionette/page.js

33%
6
2
4
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27/**
28 * 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
361module.exports = function (Marionette) {
37
38 /**
39 * Get the current page source
40 *
41 * @method source
42 */
43
440 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
590 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
740 Marionette.addCommand({
75 name: 'geoLocation',
76 implemented: false
77 });
78
79 /**
80 * Set the geo location
81 *
82 * @method setGeoLocation
83 */
84
850 Marionette.addCommand({
86 name: 'setGeoLocation',
87 implemented: false
88 });
89
90};
91

/home/ubuntu/src/github.com/dalekjs/dalek-browser-firefox/lib/commands/marionette/screenshot.js

66%
3
2
1
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'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
361module.exports = function (Marionette) {
37
38 /**
39 * Returns the current visible screen as a base64 png
40 *
41 * @method screenshot
42 */
43
440 Marionette.addCommand({
45 name: 'screenshot',
46 request: {
47 to: ':marionetteId',
48 session: ':sessionId',
49 name: 'screenShot',
50 parameters: {}
51 }
52 });
53
54};
55

/home/ubuntu/src/github.com/dalekjs/dalek-browser-firefox/lib/commands/marionette/session.js

40%
5
2
3
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27/**
28 * 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
361module.exports = function (Marionette) {
37
38 /**
39 * Gets the marionette id for the current testing session
40 *
41 * @method getMarionetteID
42 */
43
440 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
580 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
720 Marionette.addCommand({
73 name: 'session',
74 request: {
75 to: ':marionetteId',
76 session: ':sessionId',
77 name: 'getSessionCapabilities'
78 }
79 });
80
81};
82

/home/ubuntu/src/github.com/dalekjs/dalek-browser-firefox/lib/commands/marionette/storage.js

100%
2
2
0
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27/**
28 * 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
361module.exports = function () {
37
38};
39

/home/ubuntu/src/github.com/dalekjs/dalek-browser-firefox/lib/commands/marionette/timeout.js

66%
3
2
1
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'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
361module.exports = function (Marionette) {
37
38 /**
39 *
40 */
41
420 Marionette.addCommand({
43 name: 'implicitWait',
44 request: {
45 to: ':marionetteId',
46 session: ':sessionId',
47 value: ':timeout',
48 name: 'setSearchTimeout'
49 }
50 });
51
52};
53

/home/ubuntu/src/github.com/dalekjs/dalek-browser-firefox/lib/commands/marionette/url.js

28%
7
2
5
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27/**
28 * 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
361module.exports = function (Marionette) {
37
38 /**
39 * Navigate to a new URL
40 *
41 * @method open
42 */
43
440 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
630 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
780 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
930 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
1080 Marionette.addCommand({
109 name: 'refresh',
110 request: {
111 to: ':marionetteId',
112 session: ':sessionId',
113 name: 'refresh'
114 }
115 });
116
117};
118

/home/ubuntu/src/github.com/dalekjs/dalek-browser-firefox/lib/commands/marionette/window.js

40%
5
2
3
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27/**
28 * 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
361module.exports = function (Marionette) {
37
38 /**
39 * Gets the current window size
40 *
41 * @method windowSize
42 */
43
440 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
610 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
760 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

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

16%
12
2
10
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27/**
28 * 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
361module.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
480 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
550 this.events.emit('marionette:cmd:cookies', {'sessionId': req.params.sessionId, 'cookie': {'name': req.body.cookie.name, 'value': req.body.cookie.value}});
560 this.events.on('marionette:cmd:cookies:response', function (data) {
570 data = JSON.parse(data);
580 var answer = {
59 sessionId: req.params.sessionId,
60 status: 0,
61 value: data.value
62 };
63
640 res.status(200);
650 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
780 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
920 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
1070 Driver.addCommand({
108 name: 'deleteCookie',
109 url: '/session/:sessionId/cookie/:name',
110 method: 'del'
111 });
112
113};
114

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

3%
55
2
53
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27/**
28 * 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
361module.exports = function (Driver) {
37
38 // check if the driver helper literal has been created yet
390 if (!Driver._helper) {
400 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
550 Driver._helper.parseElement = function (element) {
560 element = JSON.parse(element);
570 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
690 Driver._helper.parseElements = function (elements) {
700 elements = JSON.parse(elements);
710 if (!elements.value) {
720 return -1;
73 }
74
750 var dt = [];
760 elements.value.forEach(function (el) {
770 dt.push({ELEMENT: el});
78 });
79
800 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
920 Driver._helper.multiElementResponse = function (req, res, elements) {
930 var answer = {
94 sessionId: req.params.sessionId,
95 status: 0,
96 value: Driver._helper.parseElements(elements)
97 };
98
990 res.status(200);
1000 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
1120 Driver._helper.singleElementResponse = function (req, res, element) {
1130 var answer = {
114 sessionId: req.params.sessionId,
115 status: 0,
116 value: Driver._helper.parseElement(element)
117 };
118
1190 res.status(200);
1200 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
1340 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
1400 this.events.emit('marionette:cmd:element', {'sessionId': req.params.sessionId, 'selector': req.body.value});
1410 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
1590 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
1650 this.events.emit('marionette:cmd:childElement', {'sessionId': req.params.sessionId, 'elementId': req.params.elementId, 'selector': req.body.value});
1660 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
1810 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
1870 this.events.emit('marionette:cmd:elements', {'sessionId': req.params.sessionId, 'selector': req.body.value});
1880 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
2060 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
2120 this.events.emit('marionette:cmd:childElements', {'sessionId': req.params.sessionId, 'elementId': req.params.elementId, 'selector': req.body.value});
2130 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
2260 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
2430 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
2600 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
2770 Driver.addCommand({
278 name: 'clear',
279 url: '/session/:sessionId/element/:elementId/clear',
280 method: 'post'
281 });
282
2830 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
3020 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
3180 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
3340 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
3510 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
3660 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
3810 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
3960 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
4110 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
4270 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
4430 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
4590 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
4750 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
4910 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
5070 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
5250 Driver.addCommand({
526 name: 'cssProperty',
527 url: '/session/:sessionId/element/:elementId/css/:propertyName',
528 method: 'get'
529 });
530
531};
532

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

20%
10
2
8
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27/**
28 * 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
361module.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
530 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
600 this.events.emit('marionette:cmd:execute', {'sessionId': req.params.sessionId, 'value': req.body.script, 'args': req.body.args});
610 this.events.on('marionette:cmd:execute:response', function (data) {
620 data = JSON.parse(data);
630 var answer = {
64 sessionId: req.params.sessionId,
65 status: 0,
66 value: data.value
67 };
68
690 res.status(200);
700 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
940 Driver.addCommand({
95 name: 'executeAsync',
96 url: '/session/:sessionId/execute_async',
97 method: 'post',
98 params: {script: 'script', args: 'args'}
99 });
100
101};
102

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

66%
3
2
1
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'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
361module.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
480 Driver.addCommand({
49 name: 'frame',
50 url: '/session/:sessionId/frame',
51 method: 'post',
52 params: {id: 'id'}
53 });
54
55};
56

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

16%
12
2
10
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27/**
28 * 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
361module.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
510 Driver.addCommand({
52 name: 'status',
53 url: '/status',
54 method: 'get',
55 onRequest: function (req, res) {
56 // load the status from marionette
570 this.events.emit('marionette:cmd:status');
58
59 // send out the raw status response
600 this.events.on('marionette:cmd:status:response', function (data) {
610 data = JSON.parse(data);
620 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
760 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
910 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
1050 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
1190 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
1380 Driver.addCommand({
139 name: 'activateEngine',
140 url: '/session/:sessionId/ime/activate',
141 method: 'post',
142 params: {engine: 'engine'}
143 });
144
145
146};
147

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

13%
15
2
13
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27/**
28 * 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
361module.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
520 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
700 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
880 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
1060 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
1210 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
1350 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
1510 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
1680 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
1850 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
2030 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
2180 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
2320 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
2510 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

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

33%
6
2
4
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27/**
28 * 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
361module.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
460 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
600 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
740 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
910 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

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

66%
3
2
1
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'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
361module.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
460 Driver.addCommand({
47 name: 'screenshot',
48 url: '/session/:sessionId/screenshot',
49 method: 'get'
50 });
51
52};
53

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

13%
15
2
13
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27/**
28 * 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
361module.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
500 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
560 this.events.emit('marionette:cmd:getMarionetteID');
570 this.events.on('marionette:cmd:getMarionetteID:response', function (connection) {
580 this.events.emit('marionette:setMarionetteID', connection.id);
590 this.events.emit('marionette:cmd:getSession');
60 }.bind(this));
61
62 // send out the webdriver session response
630 this.events.on('marionette:cmd:getSession:response', function (session) {
640 session = JSON.parse(session);
650 res.location('http://' + this.host + ':' + this.port + '/session/' + session.value);
660 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
780 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
910 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
1050 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
1190 Driver.addCommand({
120 name: 'deleteSession',
121 url: '/session/:sessionId',
122 method: 'del'
123 });
124
125};
126

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

13%
15
2
13
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27/**
28 * 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
361module.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
460 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
620 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
770 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
920 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
1070 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
1210 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
1350 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
1510 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
1660 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
1810 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
1960 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
2100 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
2240 Driver.addCommand({
225 name: 'applicationCacheStatus',
226 url: '/session/:sessionId/application_cache/status',
227 method: 'get'
228 });
229
230};
231

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

40%
5
2
3
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27/**
28 * 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
361module.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
490 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
690 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
870 Driver.addCommand({
88 name: 'asyncScript',
89 url: '/session/:sessionId/timeouts/async_script',
90 method: 'post',
91 params: {timeout: 'ms'}
92 });
93
94};
95

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

28%
7
2
5
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27/**
28 * 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
361module.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
470 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
620 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
760 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
910 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
1060 Driver.addCommand({
107 name: 'refresh',
108 url: '/session/:sessionId/refresh',
109 method: 'post',
110 timeout: 1000
111 });
112
113};
114

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

9%
22
2
20
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27/**
28 * 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
361module.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
460 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
600 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
760 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
910 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
1070 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
1140 this.events.emit('marionette:cmd:windowSize', {'sessionId': req.params.sessionId, 'value': 'window.resizeTo("' + req.body.height + '", "' + req.body.width + '")' });
1150 this.events.on('marionette:cmd:windowSize:response', function () {
1160 var answer = {
117 sessionId: req.params.sessionId,
118 status: 0,
119 value: true
120 };
121
1220 res.status(200);
1230 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
1380 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
1550 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
1720 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
1880 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
2030 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
2190 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
2340 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
2490 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
2650 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
2810 Driver.addCommand({
282 name: 'dismissDialog',
283 url: '/session/:sessionId/dismiss_alert',
284 method: 'post'
285 });
286
287};
288

/home/ubuntu/src/github.com/dalekjs/dalek-browser-firefox/lib/marionette.js

14%
102
15
87
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27// ext. libs
281var fs = require('fs');
291var net = require('net');
301var 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
501var Marionette = function (events) {
51 // configure the marionette socket
520 this.socket = new net.Socket();
530 this.socket.on('error', this._onError.bind(this));
540 this.socket.on('data', this._onData.bind(this));
55
56 // configure marionette session container
570 this._marionetteID = null;
58
59 // store events instance
600 this.events = events;
61
62 // register marionette id setter
630 this.events.on('marionette:setMarionetteID', function (id) {
640 this._marionetteID = id;
65 }.bind(this));
66
67 // prepare the commands property
680 this.commands = {};
69
70 // prepare the last send command property
710 this._lastCommand = null;
72
73 // prepare the last message length property
740 this._lastMessageLength = null;
75
76 // load the commands
770 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
891Marionette.prototype.connect = function (marionettePort) {
900 var deferred = Q.defer();
910 this.socket.on('connect', deferred.resolve);
920 this.socket.connect(marionettePort);
930 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
1041Marionette.prototype.kill = function () {
1050 var deferred = Q.defer();
1060 this.socket.on('end', deferred.makeNodeResolver());
1070 this.socket.end();
1080 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
1201Marionette.prototype.addCommand = function (command) {
121 // generate the command function
1220 this.commands[command.name] = function (params) {
1230 var req = {};
1240 var deferred = Q.defer();
125
1260 deferred.promise.then(function (data) {
1270 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
1310 Object.keys(command.request).forEach(function (key){
132 // cookie related hack
1330 if (command.name === 'cookies' && this._parseRequestKey(command.request[key], params) === '') {
134 } else {
1350 req[key] = this._parseRequestKey(command.request[key], params);
136 }
137 }.bind(this));
138
139 // issue the command
1400 this._sendCommand(req, deferred);
141 }.bind(this);
142
143 // generate event listener for every marionette command
1440 this.events.on('marionette:cmd:' + command.name, this.commands[command.name].bind(this));
1450 return command;
146};
147
148/**
149 * Loads the marionette commands from the commands library
150 *
151 * @method _loadCommands
152 * @chainable
153 * @private
154 */
155
1561Marionette.prototype._loadCommands = function () {
1570 var dir = __dirname + '/commands/marionette/';
1580 fs.readdirSync(dir).forEach(function (file) {
1590 require(dir + file)(this);
160 }.bind(this));
1610 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
1751Marionette.prototype._parseRequestKey = function (placeholder, params) {
1760 if (typeof placeholder !== 'object' && placeholder[0] !== ':') {
1770 return placeholder;
178 }
179
180 // check the params
1810 if (!params) {
1820 params = {};
183 }
184
185 // add the marionetteID to the params
1860 if (typeof placeholder !== 'object') {
1870 params.marionetteId = this._marionetteID;
188 }
189
1900 var content = '';
1910 if (typeof placeholder !== 'object') {
1920 Object.keys(params).forEach(function (key){
1930 if (key === placeholder.substr(1)) {
1940 content = params[key];
195 }
196 }.bind(this));
197 }
198
199 // check if we have a params object (and replace also there)
2000 if (typeof placeholder === 'object') {
2010 content = {};
202
2030 Object.keys(params).forEach(function (key) {
2040 Object.keys(placeholder).forEach(function (name) {
2050 if (placeholder[name] && placeholder[name].substring(1) === key) {
2060 content[name] = params[key];
207 }
208 }.bind(this));
209 }.bind(this));
210
2110 Object.keys(placeholder).forEach(function (name) {
2120 if (placeholder[name].substr(0, 1) !== ':') {
2130 content[name] = placeholder[name];
214 }
215 }.bind(this));
216 }
217
2180 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
2301Marionette.prototype._onError = function (err) {
231 // TODO: Use the super not yet implemented dalek error handler
2320 console.log('ERR', String(err));
2330 process.exit();
2340 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
2461Marionette.prototype._onData = function (data) {
2470 var def = Q.defer();
2480 var raw = String(data);
249 // extract the header out of the raw message
2500 var colon = raw.indexOf(':');
2510 var length = raw.substr(0, colon);
2520 var msg = raw.substring(colon + 1);
253
254 // check if this is incoming data is a sibling
255 // to a previous received message
2560 if (isNaN(parseInt(length, 10))) {
2570 length = this._lastResponseLength;
258 }
259
260 // store message data
2610 this._lastResponseLength = length;
2620 this._lastResponse += msg;
2630 this._lastRawResponse += raw;
264
265 // check if the message is complete
2660 if((this._lastResponse.length + 1) >= parseInt(length, 10)) {
267 // resolve the message
2680 def.resolve(this._lastRawResponse);
269
270 // reset our message storage
2710 this._lastRawResponse = '';
2720 this._lastResponse = '';
2730 this._lastResponseLength = null;
274 }
275
276 // release the message when it is completely received
2770 Q.when(def.promise).then(function(data) {
278 // parse the message & call the resolving function
2790 var parsedMessage = this._parseMessage(data);
280 // avoid resolving the initial handshake command
2810 if (!parsedMessage.applicationType) {
2820 this._lastCommand.resolve(parsedMessage);
283 }
284
285 }.bind(this));
286
2870 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
3001Marionette.prototype._parseMessage = function (data) {
3010 var raw = String(data);
3020 var colon = raw.indexOf(':');
3030 var message = JSON.parse(raw.substring(colon + 1));
3040 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
3201Marionette.prototype._sendCommand = function (command, deferred) {
321 // serialize message
3220 var commandSerialized = JSON.stringify(command);
3230 var msg = commandSerialized.length + ':' + commandSerialized;
324 // reference promise
3250 this._lastCommand = deferred;
326 // send command
3270 this.socket.write(msg);
328
3290 return this;
330};
331
3321module.exports = Marionette;
333

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

22%
53
12
41
LineHitsSource
1/*!
2 *
3 * Copyright (c) 2013 Sebastian Golasch
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
251'use strict';
26
27// ext. libs
281var fs = require('fs');
291var Q = require('q');
301var express = require('express');
311var 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
511var WebDriverServer = function (events) {
52 // store events
530 this.events = events;
54
55 // placeholder for the webdriver server port & host
560 this.port = null;
570 this.host = null;
58
59 // configure express
600 this.app = express();
61
620 this.app.use(connect.json());
630 this.app.use(connect.urlencoded());
64
65 // load the commands
660 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
781WebDriverServer.prototype.connect = function (webdriverPort, webdriverHost) {
790 var deferred = Q.defer();
80 // store host & port
810 this.port = webdriverPort;
820 this.host = webdriverHost;
83 // start the webdriver server
840 this.listener = this.app.listen(webdriverPort, deferred.resolve);
850 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
961WebDriverServer.prototype.kill = function () {
970 var deferred = Q.defer();
980 this.listener.close(deferred.resolve);
990 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
1121WebDriverServer.prototype.addCommand = function (command) {
113 // bind the command callback (on request)
1140 var cb = command.onRequest ? command.onRequest.bind(this) : this._onRequest.bind(this, command);
115 // register the REST endpoint
1160 this.app[command.method](command.url, cb);
1170 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
1281WebDriverServer.prototype._loadCommands = function () {
1290 var dir = __dirname + '/commands/webdriver/';
1300 fs.readdirSync(dir).forEach(function (file) {
1310 require(dir + file)(this);
132 }.bind(this));
1330 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
1491WebDriverServer.prototype._onRequest = function (command, req, res) {
150 // extract the request paramters
1510 var parameters = {};
1520 Object.keys(req.params).forEach(function (key) {
1530 parameters[key] = req.params[key];
154 });
155
156 // add paramters extracted from the post body if necessary
1570 if (command.params) {
1580 Object.keys(command.params).forEach(function (key) {
1590 parameters[key] = req.body[command.params[key]];
160 });
161 }
162
163 // trigger the marionette command
1640 this.events.emit('marionette:cmd:' + command.name, parameters);
165
166 // generate & send the webdriver response when the command has been executed by marionette
1670 this.events.on('marionette:cmd:' + command.name + ':response', function (data) {
1680 var parsedData = {};
169
1700 try {
1710 parsedData = JSON.parse(data);
172 } catch (e) {
1730 parsedData = data;
174 }
175
1760 data = parsedData;
1770 var answer = { sessionId: parameters.sessionId, status: 0};
178
179 // check if we need to send a value with the response
1800 if (data.value || data.value === false) {
1810 answer.value = data.value;
182 }
183
1840 res.status(200);
1850 res.send(JSON.stringify(answer));
186
187 }.bind(this));
188
1890 return this;
190};
191
1921module.exports = WebDriverServer;
193