Coverage

14%
506
75
431

/home/ubuntu/src/github.com/dalekjs/dalek-driver-native/index.js

12%
87
11
76
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');
30
31// int. libs
321var WD = null;
33
34// try/catch loading of the webdriver, so we can
35// fall back to canary builds
361try {
371 WD = require('dalek-internal-webdriver');
38} catch (e) {
390 try {
400 WD = require('dalek-internal-webdriver-canary');
41 } catch (e) {
420 throw e;
43 }
44}
45
46/**
47 * Loads the webdriver client,
48 * launches the browser,
49 * initializes al object properties,
50 * binds to browser events
51 *
52 * @param {object} opts Options needed to kick off the driver
53 * @constructor
54 */
55
561var DriverNative = function (opts) {
57 // get the browser configuration & the browser module
580 var browserConf = opts.browserConf;
590 var browser = opts.browserMo;
60
61 // prepare properties
620 this._initializeProperties(opts);
63
64 // create a new webdriver client instance
650 this.webdriverClient = new WD(browser, this.events);
66
67 // listen on browser events
680 this._startBrowserEventListeners(browser);
69
70 // store desired capabilities of this session
710 this.desiredCapabilities = browser.desiredCapabilities;
720 this.browserDefaults = browser.driverDefaults;
73
74 // launch the browser & when the browser launch
75 // promise is fullfilled, issue the driver:ready event
76 // for the particular browser
770 browser
78 .launch(browserConf, this.reporterEvents, this.config)
79 .then(this.events.emit.bind(this.events, 'driver:ready:native:' + this.browserName, browser));
80};
81
82/**
83 * Launches the browsers to test
84 * and handles the webdriver requests & responses
85 *
86 * @module Driver
87 * @class DriverNative
88 * @namespace Dalek
89 * @part DriverNative
90 * @api
91 */
92
931DriverNative.prototype = {
94
95 /**
96 * Initializes the driver properties
97 *
98 * @method _initializeProperties
99 * @param {object} opts Options needed to kick off the driver
100 * @chainable
101 * @private
102 */
103
104 _initializeProperties: function (opts) {
105 // prepare properties
1060 this.actionQueue = [];
1070 this.config = opts.config;
1080 this.lastCalledUrl = null;
1090 this.driverStatus = {};
1100 this.sessionStatus = {};
111 // store injcted options in object properties
1120 this.events = opts.events;
1130 this.reporterEvents = opts.reporter;
1140 this.browserName = opts.browser;
1150 return this;
116 },
117
118 /**
119 * Binds listeners on browser events
120 *
121 * @method _initializeProperties
122 * @param {object} browser Browser module
123 * @chainable
124 * @private
125 */
126
127 _startBrowserEventListeners: function (browser) {
1280 this.reporterEvents.on('browser:notify:data:' + this.browserName, function (data) {
1290 this.desiredCapabilities = data.desiredCapabilities;
1300 this.browserDefaults = data.defaults;
131 }.bind(this));
132 // issue the kill command to the browser, when all tests are completed
1330 this.events.on('tests:complete:native:' + this.browserName, browser.kill.bind(browser));
134 // clear the webdriver session, when all tests are completed
1350 this.events.on('tests:complete:native:' + this.browserName, this.webdriverClient.closeSession.bind(this.webdriverClient));
1360 return this;
137 },
138
139 /**
140 * Checks if a webdriver session has already been established,
141 * if not, create a new one
142 *
143 * @method start
144 * @return {object} promise Driver promise
145 */
146
147 start: function () {
1480 var deferred = Q.defer();
149
150 // check if a session is already active,
151 // if so, reuse that one
1520 if(this.webdriverClient.hasSession()) {
1530 deferred.resolve();
1540 return deferred.promise;
155 }
156
157 // start a browser session
1580 this._startBrowserSession(deferred, this.desiredCapabilities, this.browserDefaults);
159
1600 return deferred.promise;
161 },
162
163 /**
164 * Creates a new webdriver session
165 * Gets the driver status
166 * Gets the session status
167 * Resolves the promise (e.g. let them tests run)
168 *
169 * @method _startBrowserSession
170 * @param {object} deferred Browser session deferred
171 * @chainable
172 * @private
173 */
174
175 _startBrowserSession: function (deferred, desiredCapabilities, defaults) {
1760 var viewport = this.config.get('viewport');
177
178 // start a session, transmit the desired capabilities
1790 var promise = this.webdriverClient.createSession({desiredCapabilities: desiredCapabilities});
180
181 // set the default viewport if supported by the browser
1820 if (defaults.viewport) {
1830 promise = promise.then(this.webdriverClient.setWindowSize.bind(this.webdriverClient, viewport.width, viewport.height));
184 }
185
186 // get the driver status if supported by the browser
1870 if (defaults.status === true) {
1880 promise = promise
189 .then(this.webdriverClient.status.bind(this.webdriverClient))
190 .then(this._driverStatus.bind(this));
191 } else {
1920 promise = promise.then(this._driverStatus.bind(this, JSON.stringify({value: defaults.status})));
193 }
194
195 // get the session info if supported by the browser
1960 if (defaults.sessionInfo === true) {
1970 promise = promise
198 .then(this.webdriverClient.sessionInfo.bind(this.webdriverClient))
199 .then(this._sessionStatus.bind(this));
200 } else {
2010 promise = promise.then(this._driverStatus.bind(this, JSON.stringify({value: defaults.sessionInfo})));
202 }
203
204 // finally resolve the deferred
2050 promise.then(deferred.resolve);
2060 return this;
207 },
208
209 /**
210 * Starts to execution of a batch of tests
211 *
212 * @method end
213 * @chainable
214 */
215
216 end: function () {
2170 var result = Q.resolve();
218
219 // loop through all promises created by the remote methods
220 // this is synchronous, so it waits if a method is finished before
221 // the next one will be executed
2220 this.actionQueue.forEach(function (f) {
2230 result = result.then(f);
224 });
225
226 // flush the queue & fire an event
227 // when the queue finished its executions
2280 result.then(this.flushQueue.bind(this));
2290 return this;
230 },
231
232 /**
233 * Flushes the action queue (e.g. commands that should be send to the wbdriver server)
234 *
235 * @method flushQueue
236 * @chainable
237 */
238
239 flushQueue: function () {
240 // clear the action queue
2410 this.actionQueue = [];
242 // emit the run.complete event
2430 this.events.emit('driver:message', {key: 'run.complete', value: null});
2440 return this;
245 },
246
247 /**
248 * Loads the browser session status
249 *
250 * @method _sessionStatus
251 * @param {object} sessionInfo Session information
252 * @return {object} promise Browser session promise
253 * @private
254 */
255
256 _sessionStatus: function (sessionInfo) {
2570 var defer = Q.defer();
2580 this.sessionStatus = JSON.parse(sessionInfo).value;
2590 this.events.emit('driver:sessionStatus:native:' + this.browserName, this.sessionStatus);
2600 defer.resolve();
2610 return defer.promise;
262 },
263
264 /**
265 * Loads the browser driver status
266 *
267 * @method _driverStatus
268 * @param {object} statusInfo Driver status information
269 * @return {object} promise Driver status promise
270 * @private
271 */
272
273 _driverStatus: function (statusInfo) {
2740 var defer = Q.defer();
2750 this.driverStatus = JSON.parse(statusInfo).value;
2760 this.events.emit('driver:status:native:' + this.browserName, this.driverStatus);
2770 defer.resolve();
2780 return defer.promise;
279 },
280
281 /**
282 * Creates an anonymus function that calls a webdriver
283 * method that has no return value, emits an empty result event
284 * if the function has been run
285 * TODO: Name is weird, should be saner
286 *
287 * @method _createNonReturnee
288 * @param {string} fnName Name of the webdriver function that should be called
289 * @return {function} fn
290 * @private
291 */
292
293 _createNonReturnee: function (fnName) {
2940 return this._actionQueueNonReturneeTemplate.bind(this, fnName);
295 },
296
297 /**
298 * Generates a chain of webdriver calls for webdriver
299 * methods that don't have a return value
300 * TODO: Name is weird, should be saner
301 *
302 * @method _actionQueueNonReturneeTemplate
303 * @param {string} fnName Name of the webdriver function that should be called
304 * @param {string} hash Unique action hash
305 * @param {string} uuid Unique action hash
306 * @chainable
307 * @private
308 */
309
310 _actionQueueNonReturneeTemplate:function (fnName, hash, uuid) {
3110 this.actionQueue.push(this.webdriverClient[fnName].bind(this.webdriverClient));
3120 this.actionQueue.push(this._generateDummyDriverMessageFn.bind(this, fnName, hash, uuid));
3130 return this;
314 },
315
316 /**
317 * Creates a driver notification with an empty value
318 * TODO: Name is weird, should be saner
319 *
320 * @method _generateDummyDriverMessageFn
321 * @param {string} fnName Name of the webdriver function that should be called
322 * @param {string} hash Unique action hash
323 * @param {string} uuid Unique action hash
324 * @return {object} promise Driver message promise
325 * @private
326 */
327
328 _generateDummyDriverMessageFn: function (fnName, hash, uuid) {
3290 var deferred = Q.defer();
3300 this.events.emit('driver:message', {key: fnName, value: null, uuid: uuid, hash: hash});
3310 deferred.resolve();
3320 return deferred.promise;
333 }
334};
335
336/**
337 * Determines if the driver is a "multi" browser driver,
338 * e.g. can handle more than one browser
339 *
340 * @method isMultiBrowser
341 * @return {bool} isMultiBrowser Driver can handle more than one browser
342 */
343
3441module.exports.isMultiBrowser = function () {
3450 return true;
346};
347
348/**
349 * Verifies a browser request
350 * TODO: Still a noop, need to add "verify the browser" logic
351 *
352 * @method verifyBrowser
353 * @return {bool} isVerifiedBrowser Driver can handle this browser
354 */
355
3561module.exports.verifyBrowser = function () {
3570 return true;
358};
359
360/**
361 * Creates a new driver instance
362 *
363 * @method create
364 * @param {object} opts Options needed to kick off the driver
365 * @return {DriverNative} driver
366 */
367
3681module.exports.create = function (opts) {
369 // load the remote command helper methods
3700 var dir = __dirname + '/lib/commands/';
3710 fs.readdirSync(dir).forEach(function (file) {
3720 require(dir + file)(DriverNative);
373 });
374
3750 return new DriverNative(opts);
376};
377

/home/ubuntu/src/github.com/dalekjs/dalek-driver-native/lib/commands/cookie.js

15%
26
4
22
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');
29
30/**
31 * Cookie related methods
32 *
33 * @module Driver
34 * @class Cookie
35 * @namespace Dalek.DriverNative.Commands
36 */
37
381var Cookie = {
39
40 /**
41 * Sets an cookie
42 *
43 * @method setCookie
44 * @param {string} name Name of the cookie
45 * @param {string} contents Contents of the cookie
46 * @param {string} hash Unique hash of that fn call
47 * @chainable
48 */
49
50 setCookie: function (name, contents, hash) {
510 this.actionQueue.push(this.webdriverClient.setCookie.bind(this.webdriverClient, {name: name, value: contents}));
520 this.actionQueue.push(this._setCookieCb.bind(this, name, contents, hash));
530 return this;
54 },
55
56 /**
57 * Sends out an event with the results of the `setCookie` call
58 *
59 * @method _setCookieCb
60 * @param {string} name Name of the cookie
61 * @param {string} contents Contents of the cookie
62 * @param {string} hash Unique hash of that fn call
63 * @return {object} promise Exists promise
64 * @private
65 */
66
67 _setCookieCb: function (name, contents, hash) {
680 var deferred = Q.defer();
690 this.events.emit('driver:message', {key: 'setCookie', value: name, contents: contents, uuid: hash, hash: hash});
700 deferred.resolve();
710 return deferred.promise;
72 },
73
74 /**
75 * Retrieves an cookie
76 *
77 * @method cookie
78 * @param {string} name Name of the cookie
79 * @param {string} cookie Expected contents of the cookie
80 * @param {string} hash Unique hash of that fn call
81 * @chainable
82 */
83
84 cookie: function (name, cookie, hash) {
850 this.actionQueue.push(this.webdriverClient.getCookie.bind(this.webdriverClient, name));
860 this.actionQueue.push(this._cookieCb.bind(this, name, hash));
870 return this;
88 },
89
90 /**
91 * Sends out an event with the results of the `setCookie` call
92 *
93 * @method _cookieCb
94 * @param {string} name Name of the cookie
95 * @param {string} expected Expected contents of the cookie
96 * @param {string} hash Unique hash of that fn call
97 * @param {string} result Serialized JSON with the reuslts of the exists call
98 * @return {object} promise Exists promise
99 * @private
100 */
101
102 _cookieCb: function (name, expected, hash, res) {
1030 var deferred = Q.defer();
1040 var cookies = JSON.parse(res).value;
1050 var cookie = false;
1060 cookies.forEach(function (cookieItem) {
1070 if (cookieItem.name === name) {
1080 cookie = cookieItem.value;
109 }
110 });
111
1120 this.events.emit('driver:message', {key: 'cookie', value: cookie, name: name, expected: expected, uuid: hash, hash: hash});
1130 deferred.resolve();
1140 return deferred.promise;
115 },
116};
117
118/**
119 * Mixes in cookie methods
120 *
121 * @param {Dalek.DriverNative} DalekNative Native driver base class
122 * @return {Dalek.DriverNative} DalekNative Native driver base class
123 */
124
1251module.exports = function (DalekNative) {
126 // mixin methods
1270 Object.keys(Cookie).forEach(function (fn) {
1280 DalekNative.prototype[fn] = Cookie[fn];
129 });
130
1310 return DalekNative;
132};
133

/home/ubuntu/src/github.com/dalekjs/dalek-driver-native/lib/commands/element.js

2%
170
4
166
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');
29
30/**
31 * Element related methods
32 *
33 * @module Driver
34 * @class Element
35 * @namespace Dalek.DriverNative.Commands
36 */
37
381var Element = {
39
40 /**
41 * Checks if an element exists
42 *
43 * @method exists
44 * @param {string} selector Selector expression to find the element
45 * @param {string} hash Unique hash of that fn call
46 * @chainable
47 */
48
49 exists: function (selector, hash) {
500 this.actionQueue.push(this.webdriverClient.element.bind(this.webdriverClient, selector));
510 this.actionQueue.push(this._existsCb.bind(this, selector, hash));
520 return this;
53 },
54
55 /**
56 * Sends out an event with the results of the `exists` call
57 *
58 * @method _existsCb
59 * @param {string} selector Selector expression to find the element
60 * @param {string} hash Unique hash of that fn call
61 * @param {string} result Serialized JSON with the reuslts of the exists call
62 * @return {object} promise Exists promise
63 * @private
64 */
65
66 _existsCb: function (selector, hash, result) {
670 var deferred = Q.defer();
680 this.events.emit('driver:message', {key: 'exists', selector: selector, hash: hash, value: (JSON.parse(result).value === -1 || JSON.parse(result).status === 7 ? 'false' : 'true')});
690 deferred.resolve();
700 return deferred.promise;
71 },
72
73 /**
74 * Checks if an element is visible
75 *
76 * @method visible
77 * @param {string} selector Selector expression to find the element
78 * @param {string} hash Unique hash of that fn call
79 * @chainable
80 */
81
82 visible: function (selector, hash) {
830 this.actionQueue.push(this.webdriverClient.element.bind(this.webdriverClient, selector));
840 this.actionQueue.push(this.webdriverClient.displayed.bind(this.webdriverClient, selector));
850 this.actionQueue.push(this._visibleCb.bind(this, selector, hash));
860 return this;
87 },
88
89 /**
90 * Sends out an event with the results of the `visible` call
91 *
92 * @method _visibleCb
93 * @param {string} selector Selector expression to find the element
94 * @param {string} hash Unique hash of that fn call
95 * @param {string} result Serialized JSON with the reuslts of the visible call
96 * @return {object} promise Visible promise
97 * @private
98 */
99
100 _visibleCb: function (selector, hash, result) {
1010 var deferred = Q.defer();
1020 this.events.emit('driver:message', {key: 'visible', selector: selector, hash: hash, value: JSON.parse(result).value});
1030 deferred.resolve();
1040 return deferred.promise;
105 },
106
107 /**
108 * Checks if an element has the expected text
109 *
110 * @method text
111 * @param {string} selector Selector expression to find the element
112 * @param {string} expected The expected text content
113 * @param {string} hash Unique hash of that fn call
114 * @chainable
115 */
116
117 text: function (selector, expected, hash) {
1180 this.actionQueue.push(this.webdriverClient.element.bind(this.webdriverClient, selector));
1190 this.actionQueue.push(this.webdriverClient.text.bind(this.webdriverClient, selector));
1200 this.actionQueue.push(this._textCb.bind(this, selector, hash, expected));
1210 return this;
122 },
123
124 /**
125 * Sends out an event with the results of the `text` call
126 *
127 * @method _textCb
128 * @param {string} selector Selector expression to find the element
129 * @param {string} hash Unique hash of that fn call
130 * @param {string} expected The expected text content
131 * @param {string} result Serialized JSON with the reuslts of the text call
132 * @return {object} Promise
133 * @private
134 */
135
136 _textCb: function (selector, hash, expected, result) {
1370 var deferred = Q.defer();
1380 this.events.emit('driver:message', {key: 'text', hash: hash, expected: expected, selector: selector, value: JSON.parse(result).value});
1390 deferred.resolve();
1400 return deferred.promise;
141 },
142
143 /**
144 * Checks if an element has the expected css property/value pairs
145 *
146 * @method css
147 * @param {string} selector Selector expression to find the element
148 * @param {string} property The css property to check
149 * @param {string} expected The expected css value
150 * @param {string} hash Unique hash of that fn call
151 * @chainable
152 */
153
154 css: function (selector, property, expected, hash) {
1550 this.actionQueue.push(this.webdriverClient.element.bind(this.webdriverClient, selector));
1560 this.actionQueue.push(this.webdriverClient.cssProperty.bind(this.webdriverClient, property));
1570 this.actionQueue.push(this._cssCb.bind(this, selector, property, hash, expected));
1580 return this;
159 },
160
161 /**
162 * Sends out an event with the results of the `css` call
163 *
164 * @method _cssCb
165 * @param {string} selector Selector expression to find the element
166 * @param {string} property The css property to check
167 * @param {string} expected The expected css value
168 * @param {string} hash Unique hash of that fn call
169 * @param {string} result Serialized JSON with the reuslts of the text call
170 * @return {object} Promise
171 * @private
172 */
173
174 _cssCb: function (selector, property, hash, expected, result) {
1750 var deferred = Q.defer();
1760 this.events.emit('driver:message', {key: 'css', hash: hash, property: property, expected: expected, selector: selector, value: JSON.parse(result).value});
1770 deferred.resolve();
1780 return deferred.promise;
179 },
180
181 /**
182 * Checks th width of an element
183 *
184 * @method width
185 * @param {string} selector Selector expression to find the element
186 * @param {string} expected The expected width value
187 * @param {string} hash Unique hash of that fn call
188 * @chainable
189 */
190
191 width: function (selector, expected, hash) {
1920 this.actionQueue.push(this.webdriverClient.element.bind(this.webdriverClient, selector));
1930 this.actionQueue.push(this.webdriverClient.size.bind(this.webdriverClient));
1940 this.actionQueue.push(this._widthCb.bind(this, selector, hash, expected));
1950 return this;
196 },
197
198 /**
199 * Sends out an event with the results of the `width` call
200 *
201 * @method _widthCb
202 * @param {string} selector Selector expression to find the element
203 * @param {string} expected The expected width value
204 * @param {string} hash Unique hash of that fn call
205 * @param {string} result Serialized JSON with the reuslts of the text call
206 * @return {object} Promise
207 * @private
208 */
209
210 _widthCb: function (selector, hash, expected, result) {
2110 var deferred = Q.defer();
2120 this.events.emit('driver:message', {key: 'width', hash: hash, expected: expected, selector: selector, value: JSON.parse(result).value.width});
2130 deferred.resolve();
2140 return deferred.promise;
215 },
216
217 /**
218 * Checks th height of an element
219 *
220 * @method height
221 * @param {string} selector Selector expression to find the element
222 * @param {string} expected The expected height value
223 * @param {string} hash Unique hash of that fn call
224 * @chainable
225 */
226
227 height: function (selector, expected, hash) {
2280 this.actionQueue.push(this.webdriverClient.element.bind(this.webdriverClient, selector));
2290 this.actionQueue.push(this.webdriverClient.size.bind(this.webdriverClient));
2300 this.actionQueue.push(this._heightCb.bind(this, selector, hash, expected));
2310 return this;
232 },
233
234 /**
235 * Sends out an event with the results of the `height` call
236 *
237 * @method _heightCb
238 * @param {string} selector Selector expression to find the element
239 * @param {string} expected The expected height value
240 * @param {string} hash Unique hash of that fn call
241 * @param {string} result Serialized JSON with the reuslts of the text call
242 * @return {object} Promise
243 * @private
244 */
245
246 _heightCb: function (selector, hash, expected, result) {
2470 var deferred = Q.defer();
2480 this.events.emit('driver:message', {key: 'height', hash: hash, expected: expected, selector: selector, value: JSON.parse(result).value.height});
2490 deferred.resolve();
2500 return deferred.promise;
251 },
252
253 /**
254 * Checks if an element has an attribute with the expected value
255 *
256 * @method attribute
257 * @param {string} selector Selector expression to find the element
258 * @param {string} attribute The attribute that should be checked
259 * @param {string} expected The expected text content
260 * @param {string} hash Unique hash of that fn call
261 * @chainable
262 */
263
264 attribute: function (selector, attribute, expected, hash) {
2650 this.actionQueue.push(this.webdriverClient.element.bind(this.webdriverClient, selector));
2660 this.actionQueue.push(this.webdriverClient.getAttribute.bind(this.webdriverClient, attribute));
2670 this.actionQueue.push(this._attributeCb.bind(this, selector, hash, attribute, expected));
2680 return this;
269 },
270
271 /**
272 * Sends out an event with the results of the `attribute` call
273 *
274 * @method _attributeCb
275 * @param {string} selector Selector expression to find the element
276 * @param {string} hash Unique hash of that fn call
277 * @param {string} attribute The attribute that should be checked
278 * @param {string} expected The expected attribute content
279 * @param {string} result Serialized JSON with the results of the attribute call
280 * @return {object} promise Attribute promise
281 * @private
282 */
283
284 _attributeCb: function (selector, hash, attribute, expected, result) {
2850 var deferred = Q.defer();
2860 this.events.emit('driver:message', {key: 'attribute', selector: selector, hash: hash, expected: expected, value: JSON.parse(result).value });
2870 deferred.resolve();
2880 return deferred.promise;
289 },
290
291 /**
292 * Checks if an element has the expected value
293 *
294 * @method val
295 * @param {string} selector Selector expression to find the element
296 * @param {string} expected The expected content
297 * @param {string} hash Unique hash of that fn call
298 * @chainable
299 */
300
301 val: function (selector, expected, hash) {
3020 this.actionQueue.push(this.webdriverClient.element.bind(this.webdriverClient, selector));
3030 this.actionQueue.push(this.webdriverClient.getAttribute.bind(this.webdriverClient, 'value'));
3040 this.actionQueue.push(this._valCb.bind(this, selector, hash, expected));
3050 return this;
306 },
307
308 /**
309 * Sends out an event with the results of the `val` call
310 *
311 * @method _valCb
312 * @param {string} selector Selector expression to find the element
313 * @param {string} hash Unique hash of that fn call
314 * @param {string} expected The expected content
315 * @param {string} result Serialized JSON with the results of the val call
316 * @return {object} Promise
317 * @private
318 */
319
320 _valCb: function (selector, hash, expected, result) {
3210 var deferred = Q.defer();
3220 this.events.emit('driver:message', {key: 'val', selector: selector, hash: hash, expected: expected, value: JSON.parse(result).value });
3230 deferred.resolve();
3240 return deferred.promise;
325 },
326
327 /**
328 * Checks if an element is selected
329 *
330 * @method selected
331 * @param {string} selector Selector expression to find the element
332 * @param {string} expected The expected content
333 * @param {string} hash Unique hash of that fn call
334 * @chainable
335 */
336
337 selected: function (selector, expected, hash) {
3380 this.actionQueue.push(this.webdriverClient.element.bind(this.webdriverClient, selector));
3390 this.actionQueue.push(this.webdriverClient.selected.bind(this.webdriverClient));
3400 this.actionQueue.push(this._selectedCb.bind(this, selector, hash, expected));
3410 return this;
342 },
343
344 /**
345 * Sends out an event with the results of the `selected` call
346 *
347 * @method _selectedCb
348 * @param {string} selector Selector expression to find the element
349 * @param {string} hash Unique hash of that fn call
350 * @param {string} expected The expected content
351 * @param {string} result Serialized JSON with the results of the selected call
352 * @return {object} Promise
353 * @private
354 */
355
356 _selectedCb: function (selector, hash, expected, result) {
3570 var deferred = Q.defer();
3580 this.events.emit('driver:message', {key: 'selected', selector: selector, hash: hash, expected: expected, value: JSON.parse(result).value });
3590 deferred.resolve();
3600 return deferred.promise;
361 },
362
363 /**
364 * Checks if an element is enabled
365 *
366 * @method enabled
367 * @param {string} selector Selector expression to find the element
368 * @param {string} expected The expected content
369 * @param {string} hash Unique hash of that fn call
370 * @chainable
371 */
372
373 enabled: function (selector, expected, hash) {
3740 this.actionQueue.push(this.webdriverClient.element.bind(this.webdriverClient, selector));
3750 this.actionQueue.push(this.webdriverClient.enabled.bind(this.webdriverClient));
3760 this.actionQueue.push(this._enabledCb.bind(this, selector, hash, expected));
3770 return this;
378 },
379
380 /**
381 * Sends out an event with the results of the `enabled` call
382 *
383 * @method _enabledCb
384 * @param {string} selector Selector expression to find the element
385 * @param {string} hash Unique hash of that fn call
386 * @param {string} expected The expected content
387 * @param {string} result Serialized JSON with the results of the selected call
388 * @return {object} Promise
389 * @private
390 */
391
392 _enabledCb: function (selector, hash, expected, result) {
3930 var deferred = Q.defer();
3940 this.events.emit('driver:message', {key: 'enabled', selector: selector, hash: hash, expected: expected, value: JSON.parse(result).value });
3950 deferred.resolve();
3960 return deferred.promise;
397 },
398
399 /**
400 * Submits a form
401 *
402 * @method submit
403 * @param {string} selector Selector expression to find the element
404 * @param {string} hash Unique hash of that fn call
405 * @param {string} uuid Unique hash of that fn call
406 * @chainable
407 */
408
409 submit: function (selector, hash, uuid) {
4100 this.actionQueue.push(this.webdriverClient.element.bind(this.webdriverClient, selector));
4110 this.actionQueue.push(this.webdriverClient.submit.bind(this.webdriverClient));
4120 this.actionQueue.push(this._submitCb.bind(this, selector, hash, uuid));
4130 return this;
414 },
415
416 /**
417 * Sends out an event with the results of the `submit` call
418 *
419 * @method _submitCb
420 * @param {string} selector Selector expression to find the element
421 * @param {string} hash Unique hash of that fn call
422 * @param {string} uuid Unique hash of that fn call
423 * @return {object} promise Click promise
424 * @private
425 */
426
427 _submitCb: function (selector, hash, uuid) {
4280 var deferred = Q.defer();
4290 this.events.emit('driver:message', {key: 'submit', value: selector, uuid: uuid, hash: hash});
4300 deferred.resolve();
4310 return deferred.promise;
432 },
433
434 /**
435 * Clicks an element
436 *
437 * @method click
438 * @param {string} selector Selector expression to find the element
439 * @param {string} hash Unique hash of that fn call
440 * @param {string} uuid Unique hash of that fn call
441 * @chainable
442 */
443
444 click: function (selector, hash, uuid) {
4450 this.actionQueue.push(this.webdriverClient.element.bind(this.webdriverClient, selector));
4460 this.actionQueue.push(this.webdriverClient.click.bind(this.webdriverClient));
4470 this.actionQueue.push(this._clickCb.bind(this, selector, hash, uuid));
4480 return this;
449 },
450
451 /**
452 * Sends out an event with the results of the `click` call
453 *
454 * @method _clickCb
455 * @param {string} selector Selector expression to find the element
456 * @param {string} hash Unique hash of that fn call
457 * @param {string} uuid Unique hash of that fn call
458 * @return {object} promise Click promise
459 * @private
460 */
461
462 _clickCb: function (selector, hash, uuid) {
4630 var deferred = Q.defer();
4640 this.events.emit('driver:message', {key: 'click', value: selector, uuid: uuid, hash: hash});
4650 deferred.resolve();
4660 return deferred.promise;
467 },
468
469 /**
470 * Scrolls from an element to a location defined in pixels
471 *
472 * @method scroll
473 * @param {string} selector Selector expression to find the element
474 * @param {object} options X offset, Y offset, Speed
475 * @param {string} hash Unique hash of that fn call
476 * @param {string} uuid Unique hash of that fn call
477 * @chainable
478 */
479
480 scroll: function (selector, options, hash, uuid) {
4810 this.actionQueue.push(this.webdriverClient.element.bind(this.webdriverClient, selector, options));
4820 this.actionQueue.push(this.webdriverClient.scroll.bind(this.webdriverClient));
4830 this.actionQueue.push(this._clickCb.bind(this, selector, options, hash, uuid));
4840 return this;
485 },
486
487 /**
488 * Sends out an event with the results of the `scroll` call
489 *
490 * @method _scrollCb
491 * @param {string} selector Selector expression to find the element
492 * @param {object} options X offset, Y offset, Speed
493 * @param {string} hash Unique hash of that fn call
494 * @param {string} uuid Unique hash of that fn call
495 * @return {object} promise Scroll promise
496 * @private
497 */
498
499 _scrollCb: function (selector, options, hash, uuid) {
5000 var deferred = Q.defer();
5010 this.events.emit('driver:message', {key: 'scroll', value: selector, uuid: uuid, hash: hash});
5020 deferred.resolve();
5030 return deferred.promise;
504 },
505
506 /**
507 * Clicks an element
508 *
509 * @method click
510 * @param {string} selector Selector expression to find the element
511 * @param {string} hash Unique hash of that fn call
512 * @chainable
513 */
514
515 type: function (selector, keystrokes, hash) {
5160 this.actionQueue.push(this.webdriverClient.element.bind(this.webdriverClient, selector));
5170 this.actionQueue.push(this.webdriverClient.element.bind(this.webdriverClient, selector));
5180 this.actionQueue.push(this.webdriverClient.val.bind(this.webdriverClient, keystrokes));
5190 this.actionQueue.push(this._typeCb.bind(this, selector, keystrokes, hash));
5200 return this;
521 },
522
523 /**
524 * Sends out an event with the results of the `type` call
525 *
526 * @method _typeCb
527 * @param {string} selector Selector expression to find the element
528 * @param {string} hash Unique hash of that fn call
529 * @return {object} promise Type promise
530 * @private
531 */
532
533 _typeCb: function (selector, keystrokes, hash) {
5340 var deferred = Q.defer();
5350 this.events.emit('driver:message', {key: 'type', value: selector, keystrokes: keystrokes, uuid: hash, hash: hash});
5360 deferred.resolve();
5370 return deferred.promise;
538 },
539
540 /**
541 * Sends keys to an element (whether or not it is an input)
542 *
543 * @method sendKeys
544 * @param {string} selector Selector expression to find the element
545 * @param {string} hash Unique hash of that fn call
546 * @chainable
547 */
548
549 sendKeys: function (selector, keystrokes, hash) {
5500 this.actionQueue.push(this.webdriverClient.element.bind(this.webdriverClient, selector));
5510 this.actionQueue.push(this.webdriverClient.sendKeys.bind(this.webdriverClient, keystrokes));
5520 this.actionQueue.push(this._sendKeysCb.bind(this, selector, keystrokes, hash));
5530 return this;
554 },
555
556 /**
557 * Sends out an event with the results of the `sendKeys` call
558 *
559 * @method _sendKeysCb
560 * @param {string} selector Selector expression to find the element
561 * @param {string} hash Unique hash of that fn call
562 * @return {object} promise Type promise
563 * @private
564 */
565
566 _sendKeysCb: function (selector, keystrokes, hash) {
5670 var deferred = Q.defer();
5680 this.events.emit('driver:message', {key: 'sendKeys', value: selector, keystrokes: keystrokes, uuid: hash, hash: hash});
5690 deferred.resolve();
5700 return deferred.promise;
571 },
572
573 /**
574 * Wait for an element for a specific amount of time
575 *
576 * @method waitForElement
577 * @param {string} selector Selector expression to find the element
578 * @param {integer} timeout Time to wait in ms
579 * @param {string} hash Unique hash of that fn call
580 * @param {string} uuid Unique hash of that fn call
581 * @chainable
582 */
583
584 waitForElement: function (selector, timeout, hash, uuid) {
5850 this.actionQueue.push(this.webdriverClient.implicitWait.bind(this.webdriverClient, timeout));
5860 this.actionQueue.push(this._waitForElementCb.bind(this, selector, hash, uuid));
5870 return this;
588 },
589
590 /**
591 * Sends out an event with the results of the `waitForElement` call
592 *
593 * @method _waitForElementCb
594 * @param {string} selector Selector expression to find the element
595 * @param {string} hash Unique hash of that fn call
596 * @param {string} uuid Unique hash of that fn call
597 * @return {object} promise WaitForElement promise
598 * @private
599 */
600
601 _waitForElementCb: function (selector, hash, uuid) {
6020 var deferred = Q.defer();
6030 this.events.emit('driver:message', {key: 'waitForElement', selector: selector, uuid: uuid, hash: hash});
6040 deferred.resolve();
6050 return deferred.promise;
606 },
607
608 /**
609 * Returns the number of elements matched by the selector
610 *
611 * @method getNumberOfElements
612 * @param {string} selector Selector expression to find the elements
613 * @param {integer} expected Expected number of matched elements
614 * @param {string} uuid Unique hash of that fn call
615 * @chainable
616 */
617
618 getNumberOfElements: function (selector, expected, hash) {
6190 this.actionQueue.push(this.webdriverClient.elements.bind(this.webdriverClient, selector));
6200 this.actionQueue.push(this._getNumberOfElementsCb.bind(this, selector, hash, expected));
6210 return this;
622 },
623
624 /**
625 * Sends out an event with the results of the `getNumberOfElements` call
626 *
627 * @method _getNumberOfElementsCb
628 * @param {string} selector Selector expression to find the element
629 * @param {string} hash Unique hash of that fn call
630 * @param {integer} expected Expected number of matched elements
631 * @param {string} res Serialized JSON with the results of the getNumberOfElements call
632 * @return {object} promise GetNumberOfElements promise
633 * @private
634 */
635
636 _getNumberOfElementsCb: function (selector, hash, expected, res) {
6370 var deferred = Q.defer();
6380 var result = JSON.parse(res);
639 // check if the expression matched any element
6400 if (result.value === -1) {
6410 this.events.emit('driver:message', {key: 'numberOfElements', hash: hash, selector: selector, expected: expected, value: 0});
642 } else {
6430 this.events.emit('driver:message', {key: 'numberOfElements', selector: selector, expected: expected, hash: hash, value: result.value.length});
644 }
645
6460 deferred.resolve();
6470 return deferred.promise;
648 },
649
650
651 /**
652 * Returns the number of visible elements matched by the selector
653 *
654 * @method getNumberOfVisibleElements
655 * @param {string} selector Selector expression to find the elements
656 * @param {integer} expected Expected number of matched elements
657 * @param {string} uuid Unique hash of that fn call
658 * @chainable
659 */
660
661 getNumberOfVisibleElements: function (selector, expected, hash) {
6620 this.actionQueue.push(this.webdriverClient.elements.bind(this.webdriverClient, selector));
6630 this.actionQueue.push(function (result) {
6640 var deferred = Q.defer();
6650 var res = JSON.parse(result);
6660 var resLength = res.value.length;
6670 var curLength = 0;
6680 var visibleElement = [];
669
6700 res.value.forEach(function (element) {
6710 var fakeResponse = JSON.stringify({sessionId: res.sessionId, status: 0, value: element.ELEMENT});
6720 this.webdriverClient.options.id = element.ELEMENT;
6730 this.webdriverClient.displayed.bind(this.webdriverClient, selector)(fakeResponse).then(function (visRes) {
6740 curLength++;
6750 if (JSON.parse(visRes).value === true) {
6760 visibleElement.push(element);
677 }
6780 if (curLength === resLength) {
6790 deferred.resolve(JSON.stringify({sessionId: res.sessionId, status: 0, value: visibleElement}));
680 }
681 });
682 }.bind(this));
683
6840 return deferred.promise;
685 }.bind(this));
6860 this.actionQueue.push(this._getNumberOfVisibleElementsCb.bind(this, selector, hash, expected));
6870 return this;
688 },
689
690 /**
691 * Sends out an event with the results of the `getNumberOfVisibleElements` call
692 *
693 * @method _getNumberOfElementsCb
694 * @param {string} selector Selector expression to find the element
695 * @param {string} hash Unique hash of that fn call
696 * @param {integer} expected Expected number of matched elements
697 * @param {string} res Serialized JSON with the results of the getNumberOfVisibleElements call
698 * @return {object} promise GetNumberOfElements promise
699 * @private
700 */
701
702 _getNumberOfVisibleElementsCb: function (selector, hash, expected, res) {
7030 var deferred = Q.defer();
7040 var result = JSON.parse(res);
705
706 // check if the expression matched any element
7070 if (result.value === -1) {
7080 this.events.emit('driver:message', {key: 'numberOfVisibleElements', hash: hash, selector: selector, expected: expected, value: 0});
709 } else {
7100 this.events.emit('driver:message', {key: 'numberOfVisibleElements', selector: selector, expected: expected, hash: hash, value: result.value.length});
711 }
712
7130 deferred.resolve();
7140 return deferred.promise;
715 }
716
717};
718
719/**
720 * Mixes in element methods
721 *
722 * @param {Dalek.DriverNative} DalekNative Native driver base class
723 * @return {Dalek.DriverNative} DalekNative Native driver base class
724 */
725
7261module.exports = function (DalekNative) {
727 // mixin methods
7280 Object.keys(Element).forEach(function (fn) {
7290 DalekNative.prototype[fn] = Element[fn];
730 });
731
7320 return DalekNative;
733};
734

/home/ubuntu/src/github.com/dalekjs/dalek-driver-native/lib/commands/frame.js

25%
16
4
12
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');
29
30/**
31 * Frame related methods
32 *
33 * @module Driver
34 * @class Frame
35 * @namespace Dalek.DriverNative.Commands
36 */
37
381var Frame = {
39
40 /**
41 * Switches to frame context
42 *
43 * @method toFrame
44 * @param {string} selector Selector expression to find the element
45 * @param {string} hash Unique hash of that fn call
46 * @chainable
47 */
48
49 toFrame: function (selector, hash) {
500 if (selector !== null) {
510 this.actionQueue.push(this.webdriverClient.element.bind(this.webdriverClient, selector));
52 }
530 this.actionQueue.push(this.webdriverClient.frame.bind(this.webdriverClient));
540 this.actionQueue.push(this._frameCb.bind(this, selector, hash));
550 return this;
56 },
57
58 /**
59 * Sends out an event with the results of the `toFrame` call
60 *
61 * @method _frameCb
62 * @param {string} selector Selector expression to find the element
63 * @param {string} hash Unique hash of that fn call
64 * @param {string} result Serialized JSON with the reuslts of the toFrame call
65 * @return {object} promise Exists promise
66 * @private
67 */
68
69 _frameCb: function (selector, hash) {
700 var deferred = Q.defer();
710 this.events.emit('driver:message', {key: 'toFrame', selector: selector, hash: hash, value: true});
720 deferred.resolve();
730 return deferred.promise;
74 }
75};
76
77/**
78 * Mixes in element methods
79 *
80 * @param {Dalek.DriverNative} DalekNative Native driver base class
81 * @return {Dalek.DriverNative} DalekNative Native driver base class
82 */
83
841module.exports = function (DalekNative) {
85 // mixin methods
860 Object.keys(Frame).forEach(function (fn) {
870 DalekNative.prototype[fn] = Frame[fn];
88 });
89
900 return DalekNative;
91};
92

/home/ubuntu/src/github.com/dalekjs/dalek-driver-native/lib/commands/page.js

6%
63
4
59
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');
29
30/**
31 * Page related methods
32 *
33 * @module Driver
34 * @class Page
35 * @namespace Dalek.DriverNative.Commands
36 */
37
381var Page = {
39
40 /**
41 * This function is non operational
42 *
43 * @method noop
44 * @param {mixed} message Whatever yu like
45 * @param {string} hash Unique hash of that fn call
46 * @chainable
47 */
48
49 noop: function (message, hash) {
500 this.actionQueue.push(this._noopCb.bind(this, message, hash));
510 return this;
52 },
53
54 /**
55 * Sends out an event with the results of the `noop` call
56 *
57 * @method _noopCb
58 * @param {mixed} message Whatever yu like
59 * @param {string} hash Unique hash of that fn call
60 * @return {object} Promise
61 * @private
62 */
63
64 _noopCb: function (message, hash) {
650 var deferred = Q.defer();
660 this.events.emit('driver:message', {key: 'noop', uuid: hash, hash: hash, value: message});
670 deferred.resolve();
680 return deferred.promise;
69 },
70
71 /**
72 * Gets the HTML source of a page
73 *
74 * @method source
75 * @param {string} hash Unique hash of that fn call
76 * @chainable
77 */
78
79 source: function (hash) {
800 this.actionQueue.push(this.webdriverClient.source.bind(this.webdriverClient));
810 this.actionQueue.push(this._sourceCb.bind(this, hash));
820 return this;
83 },
84
85 /**
86 * Sends out an event with the results of the `source` call
87 *
88 * @method _sourceCb
89 * @param {string} hash Unique hash of that fn call
90 * @param {string} source Serialized JSON with the results of the source call
91 * @return {object} Promise
92 * @private
93 */
94
95 _sourceCb: function (hash, source) {
960 var deferred = Q.defer();
970 this.events.emit('driver:message', {key: 'source', uuid: hash, hash: hash, value: JSON.parse(source).value});
980 deferred.resolve();
990 return deferred.promise;
100 },
101
102 /**
103 * Checks the document title of a page
104 *
105 * @method title
106 * @param {string} expected Expected page title
107 * @param {string} hash Unique hash of that fn call
108 * @chainable
109 */
110
111 title: function (expected, hash) {
1120 this.actionQueue.push(this.webdriverClient.title.bind(this.webdriverClient));
1130 this.actionQueue.push(this._titleCb.bind(this, expected, hash));
1140 return this;
115 },
116
117 /**
118 * Sends out an event with the results of the `title` call
119 *
120 * @method _titleCb
121 * @param {string} expected Expected page title
122 * @param {string} hash Unique hash of that fn call
123 * @param {string} title Serialized JSON with the results of the title call
124 * @return {object} promise Title promise
125 * @private
126 */
127
128 _titleCb: function (expected, hash, title) {
1290 var deferred = Q.defer();
1300 this.events.emit('driver:message', {key: 'title', expected: expected, hash: hash, value: JSON.parse(title).value});
1310 deferred.resolve();
1320 return deferred.promise;
133 },
134
135 /**
136 * Checks the text of an alaert, prompt or confirm dialog
137 *
138 * @method alertText
139 * @param {string} expected Expected alert text
140 * @param {string} hash Unique hash of that fn call
141 * @chainable
142 */
143
144 alertText: function (expected, hash) {
1450 this.actionQueue.push(this.webdriverClient.alertText.bind(this.webdriverClient));
1460 this.actionQueue.push(this._alertTextCb.bind(this, expected, hash));
1470 return this;
148 },
149
150 /**
151 * Sends out an event with the results of the `alertText` call
152 *
153 * @method _alertTextCb
154 * @param {string} expected Expected alert text
155 * @param {string} hash Unique hash of that fn call
156 * @param {string} alertText Serialized JSON with the results of the alertText call
157 * @return {object} promise alertText promise
158 * @private
159 */
160
161 _alertTextCb: function (expected, hash, alertText) {
1620 var deferred = Q.defer();
1630 this.events.emit('driver:message', {key: 'alertText', expected: expected, hash: hash, value: JSON.parse(alertText).value});
1640 deferred.resolve();
1650 return deferred.promise;
166 },
167
168 /**
169 * Sends text to a javascript prompt dialog box
170 *
171 * @method promptText
172 * @param {object} dimensions New window width & height
173 * @param {string} hash Unique hash of that fn call
174 * @chainable
175 */
176
177 promptText: function (text, hash) {
1780 this.actionQueue.push(this.webdriverClient.promptText.bind(this.webdriverClient, text));
1790 this.actionQueue.push(this._promptTextCb.bind(this, text, hash));
1800 return this;
181 },
182
183 /**
184 * Sends out an event with the results of the `promptText` call
185 *
186 * @method _promptTextCb
187 * @param {object} dimensions New window width & height
188 * @param {string} hash Unique hash of that fn call
189 * @param {string} result Serialized JSON with the reuslts of the toFrame call
190 * @return {object} promise Exists promise
191 * @private
192 */
193
194 _promptTextCb: function (text, hash) {
1950 var deferred = Q.defer();
1960 this.events.emit('driver:message', {key: 'promptText', text: text, hash: hash, value: true});
1970 deferred.resolve();
1980 return deferred.promise;
199 },
200
201 /**
202 * Accepts (e.g. oressing the OK button) an javascript alert, prompt or confirm dialog
203 *
204 * @method acceptAlert
205 * @param {string} hash Unique hash of that fn call
206 * @chainable
207 */
208
209 acceptAlert: function (hash) {
2100 this.actionQueue.push(this.webdriverClient.acceptAlert.bind(this.webdriverClient));
2110 this.actionQueue.push(this._acceptAlertCb.bind(this, hash));
2120 return this;
213 },
214
215 /**
216 * Sends out an event with the results of the `acceptAlert` call
217 *
218 * @method _acceptAlertCb
219 * @param {string} hash Unique hash of that fn call
220 * @param {string} result Serialized JSON with the reuslts of the toFrame call
221 * @return {object} promise Exists promise
222 * @private
223 */
224
225 _acceptAlertCb: function (text, hash) {
2260 var deferred = Q.defer();
2270 this.events.emit('driver:message', {key: 'acceptAlert', hash: hash, value: true});
2280 deferred.resolve();
2290 return deferred.promise;
230 },
231
232 /**
233 * Accepts (e.g. oressing the OK button) an javascript alert, prompt or confirm dialog
234 *
235 * @method dismissAlert
236 * @param {string} hash Unique hash of that fn call
237 * @chainable
238 */
239
240 dismissAlert: function (hash) {
2410 this.actionQueue.push(this.webdriverClient.dismissAlert.bind(this.webdriverClient));
2420 this.actionQueue.push(this._dismissAlertCb.bind(this, hash));
2430 return this;
244 },
245
246 /**
247 * Sends out an event with the results of the `dismissAlert` call
248 *
249 * @method _dismissAlertCb
250 * @param {string} hash Unique hash of that fn call
251 * @param {string} result Serialized JSON with the reuslts of the toFrame call
252 * @return {object} promise Exists promise
253 * @private
254 */
255
256 _dismissAlertCb: function (text, hash) {
2570 var deferred = Q.defer();
2580 this.events.emit('driver:message', {key: 'dismissAlert', hash: hash, value: true});
2590 deferred.resolve();
2600 return deferred.promise;
261 },
262
263 /**
264 * Wait for a specific amount of time
265 *
266 * @method wait
267 * @param {integer} timeout Time to wait in ms
268 * @param {string} hash Unique hash of that fn call
269 * @param {string} uuid Unique hash of that fn call
270 * @chainable
271 */
272
273 wait: function (timeout, hash, uuid) {
2740 this.actionQueue.push(this.webdriverClient.implicitWait.bind(this.webdriverClient, timeout));
2750 this.actionQueue.push(this._waitCb.bind(this, timeout, hash, uuid));
2760 return this;
277 },
278
279 /**
280 * Sends out an event with the results of the `wait` call
281 *
282 * @method _waitCb
283 * @param {integer} timeout Time to wait in ms
284 * @param {string} hash Unique hash of that fn call
285 * @param {string} uuid Unique hash of that fn call
286 * @return {object} promise WaitForElement promise
287 * @private
288 */
289
290 _waitCb: function (timeout, hash, uuid) {
2910 var deferred = Q.defer();
2920 this.events.emit('driver:message', {key: 'wait', timeout: timeout, uuid: uuid, hash: hash, value: timeout + ' ms'});
2930 setTimeout(function () {
2940 deferred.resolve();
295 }.bind(this), timeout);
2960 return deferred.promise;
297 }
298
299};
300
301/**
302 * Mixes in page methods
303 *
304 * @param {Dalek.DriverNative} DalekNative Native driver base class
305 * @return {Dalek.DriverNative} DalekNative Native driver base class
306 */
307
3081module.exports = function (DalekNative) {
309 // mixin methods
3100 Object.keys(Page).forEach(function (fn) {
3110 DalekNative.prototype[fn] = Page[fn];
312 });
313
3140 return DalekNative;
315};
316

/home/ubuntu/src/github.com/dalekjs/dalek-driver-native/lib/commands/screenshot.js

49%
81
40
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 Q = require('q');
291var fs = require('fs');
30
31/**
32 * Screenshot related methods
33 *
34 * @module Driver
35 * @class Screenshot
36 * @namespace Dalek.DriverNative.Commands
37 */
38
391var Screenshot = {
40
41 /**
42 * Makes an screenshot of the current page
43 *
44 * @method screenshot
45 * @param {string} path Root directory path
46 * @param {string} pathname Pathname of the screenshot path
47 * @param {string} hash Unique hash of that fn call
48 * @param {string} uuid Unique hash of that fn call
49 * @chainable
50 */
51
52 screenshot: function (path, pathname, hash, uuid) {
530 this.actionQueue.push(this.webdriverClient.screenshot.bind(this.webdriverClient));
540 this.actionQueue.push(this._screenshotCb.bind(this, path, pathname, hash, uuid));
550 return this;
56 },
57
58 /**
59 * Sends out an event with the results of the `screenshot` call
60 * and stores the screenshot in the filesystem
61 *
62 * @method _screenshotCb
63 * @param {string} path Root directory path
64 * @param {string} pathname Pathname of the screenshot path
65 * @param {string} hash Unique hash of that fn call
66 * @param {string} uuid Unique hash of that fn call
67 * @param {string} result Serialized JSON result of the screenshot call
68 * @return {object} promise Screenshot promise
69 * @private
70 */
71
72 _screenshotCb: function (path, pathname, hash, uuid, result) {
730 var deferred = Q.defer();
74 // replace base64 metadata
750 var base64Data = JSON.parse(result).value.replace(/^data:image\/png;base64,/,'');
76 // replace placeholders
770 var realpath = this._replacePathPlaceholder(path + pathname);
78 // check if we need to add a new directory
790 this._recursiveMakeDirSync(realpath.substring(0, realpath.lastIndexOf('/')));
80 // write the screenshot
810 fs.writeFileSync(realpath, base64Data, 'base64');
820 this.events.emit('driver:message', {key: 'screenshot', value: realpath, uuid: hash, hash: hash});
830 deferred.resolve();
840 return deferred.promise;
85 },
86
87 /**
88 * Recursige mkdir helper
89 *
90 * @method _recursiveMakeDirSync
91 * @param {string} path Path to create
92 * @private
93 */
94
95 _recursiveMakeDirSync: function (path) {
960 var pathSep = require('path').sep;
970 var dirs = path.split(pathSep);
980 var root = '';
99
1000 while (dirs.length > 0) {
1010 var dir = dirs.shift();
1020 if (dir === '') {
1030 root = pathSep;
104 }
1050 if (!fs.existsSync(root + dir)) {
1060 fs.mkdirSync(root + dir);
107 }
1080 root += dir + pathSep;
109 }
110 },
111
112 /**
113 * Return the formatted os name
114 *
115 * @method _parseOS
116 * @param {string} Pathname
117 * @return {string} Formatted pathname
118 * @private
119 */
120
121 _replacePathPlaceholder: function (pathname) {
1220 pathname = pathname.replace(':browser', this.browserName);
1230 pathname = pathname.replace(':version', this._parseBrowserVersion(this.sessionStatus.version));
1240 pathname = pathname.replace(':timestamp', Math.round(new Date().getTime() / 1000));
1250 pathname = pathname.replace(':osVersion', this._parseOSVersion(this.driverStatus.os.version));
1260 pathname = pathname.replace(':os', this._parseOS(this.driverStatus.os.name));
1270 pathname = pathname.replace(':datetime', this._parseDatetime());
1280 pathname = pathname.replace(':date', this._parseDate());
1290 pathname = pathname.replace(':viewport', this._parseViewport());
1300 return pathname;
131 },
132
133 /**
134 * Return the formatted os name
135 *
136 * @method _parseOS
137 * @return {string} OS name
138 * @private
139 */
140
141 _parseOS: function (os) {
1420 var mappings = {
143 'mac': 'OSX',
144 'Mac OS X': 'OSX'
145 };
1460 return mappings[os] || 'unknown';
147 },
148
149 /**
150 * Return the formatted os version
151 *
152 * @method _parseOSVersion
153 * @return {string} OS version
154 * @private
155 */
156
157 _parseOSVersion: function (version) {
1580 var vs = version.replace(/[^0-9\\.]/g, '');
1590 vs = vs.replace(/\./g, '_');
1600 return vs;
161 },
162
163 /**
164 * Return the formatted browser version
165 *
166 * @method _parseBrowserVersion
167 * @return {string} Browser version
168 * @private
169 */
170
171 _parseBrowserVersion: function (version) {
1720 return version.replace(/\./g, '_');
173 },
174
175 /**
176 * Return the ISO 8601 formatted date
177 *
178 * @method _parseDate
179 * @param {object} optional A javascript date object. If undefined, the current date is used.
180 * @return {string} Date
181 * @private
182 */
183
184 _parseDate: function (date) {
18512 date = date ? date : new Date();
18612 var day = date.getDate();
18712 var month = date.getMonth() + 1;
18812 var year = date.getFullYear();
189
19012 month = ('0' + month).slice(-2);
19112 day = ('0' + day).slice(-2);
192
19312 return year + '-' + month + '-' + day;
194 },
195
196 /**
197 * Return the ISO 8601 formatted datetime
198 *
199 * @method _parseDatetime
200 * @param {object} optional A javascript date object. If undefined, the current date is used.
201 * @return {string} Datetime
202 * @private
203 */
204
205 _parseDatetime: function (date) {
2068 date = date ? date : new Date();
2078 var dateStr = this._parseDate();
2088 var timeStr = 'T#hours#:#minutes#:#seconds##formattedOffset#';
2098 var hours = date.getHours();
2108 var minutes = date.getMinutes();
2118 var seconds = date.getSeconds();
2128 var offsetHours = '' + Math.ceil(date.getTimezoneOffset() / 60);
2138 var offsetMinutes = '' + Math.abs(date.getTimezoneOffset() % 60);
2148 var formattedOffset;
215
2168 hours = ('0' + hours).slice(-2);
2178 minutes = ('0' + minutes).slice(-2);
2188 seconds = ('0' + seconds).slice(-2);
219
2208 if (offsetHours[0] === '-' && offsetHours.length < 3) {
2212 formattedOffset = offsetHours[0] + '0' + offsetHours[1];
2226 } else if (offsetHours.length < 2) {
2236 formattedOffset = '+0' + offsetHours;
224 }
225
2268 if (offsetMinutes.length < 2) {
2274 formattedOffset += ':0' + offsetMinutes;
228 } else {
2294 formattedOffset += ':' + offsetMinutes;
230 }
231
2328 if (offsetHours === '0' && offsetMinutes === '0') {
2332 formattedOffset = 'Z';
234 }
235
2368 timeStr = timeStr.replace('#hours#', hours);
2378 timeStr = timeStr.replace('#minutes#', minutes);
2388 timeStr = timeStr.replace('#seconds#', seconds);
2398 timeStr = timeStr.replace('#formattedOffset#', formattedOffset);
240
2418 return dateStr + timeStr;
242 },
243
244 /**
245 * Return the formatted viewport
246 *
247 * @method _parseViewport
248 * @return {string} Viewport
249 * @private
250 */
251
252 _parseViewport: function () {
2530 var viewport = this.config.get('viewport');
2540 return 'w' + viewport.width + '_h' + viewport.height;
255 }
256
257};
258
259/**
260 * Mixes in screenshot methods
261 *
262 * @param {Dalek.DriverNative} DalekNative Native driver base class
263 * @return {Dalek.DriverNative} DalekNative Native driver base class
264 */
265
2661module.exports = function (DalekNative) {
26712 if ('undefined' === typeof DalekNative) {
26812 return Screenshot;
269 }
270 // mixin methods
2710 Object.keys(Screenshot).forEach(function (fn) {
2720 DalekNative.prototype[fn] = Screenshot[fn];
273 });
274
2750 return DalekNative;
276};
277

/home/ubuntu/src/github.com/dalekjs/dalek-driver-native/lib/commands/url.js

14%
28
4
24
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');
29
30/**
31 * Url related methods
32 *
33 * @module Driver
34 * @class Url
35 * @namespace Dalek.DriverNative.Commands
36 */
37
381var Url = {
39
40 /**
41 * Navigate to a new URL
42 *
43 * @method open
44 * @param {string} url Url to navigate to
45 * @param {string} hash Unique hash of that fn call
46 * @param {string} uuid Unique hash of that fn call
47 * @chainable
48 */
49
50 open: function (url, hash, uuid) {
510 this.lastCalledUrl = url;
520 this.actionQueue.push(this.webdriverClient.url.bind(this.webdriverClient, url));
530 this.actionQueue.push(this._openCb.bind(this, url, hash, uuid));
540 return this;
55 },
56
57 /**
58 * Sends out an event with the results of the `open` call
59 *
60 * @method _openCb
61 * @param {string} url Url to navigate to
62 * @param {string} hash Unique hash of that fn call
63 * @param {string} uuid Unique hash of that fn call
64 * @return {object} promise Open promise
65 * @private
66 */
67
68 _openCb: function (url, hash, uuid) {
690 var deferred = Q.defer();
700 this.events.emit('driver:message', {key: 'open', value: url, hash: hash, uuid: uuid});
710 deferred.resolve();
720 return deferred.promise;
73 },
74
75 /**
76 * Fetches the current url
77 *
78 * @method url
79 * @param {string} expected Expected url
80 * @param {string} hash Unique hash of that fn call
81 * @chainable
82 */
83
84 url: function (expected, hash) {
850 this.actionQueue.push(this.webdriverClient.getUrl.bind(this.webdriverClient));
860 this.actionQueue.push(this._urlCb.bind(this, expected, hash));
870 return this;
88 },
89
90 /**
91 * Sends out an event with the results of the `url` call
92 *
93 * @method _urlCb
94 * @param {string} expected Expected url
95 * @param {string} hash Unique hash of that fn call
96 * @param {string} url Serialized JSON result of url call
97 * @return {object} promise Url promise
98 * @private
99 */
100
101 _urlCb: function (expected, hash, url) {
1020 var deferred = Q.defer();
1030 this.events.emit('driver:message', {key: 'url', expected: expected, hash: hash, value: JSON.parse(url).value});
1040 deferred.resolve();
1050 return deferred.promise;
106 },
107
108 /**
109 * Navigate backwards in the browser history, if possible.
110 *
111 * @method back
112 * @param {string} hash Unique hash of that fn call
113 * @param {string} uuid Unique hash of that fn call
114 * @chainable
115 */
116
117 back: function (hash, uuid) {
1180 this._createNonReturnee('back')(hash, uuid);
1190 return this;
120 },
121
122 /**
123 * Navigate forwards in the browser history, if possible.
124 *
125 * @method forward
126 * @param {string} hash Unique hash of that fn call
127 * @param {string} uuid Unique hash of that fn call
128 * @chainable
129 */
130
131 forward: function (hash, uuid) {
1320 this._createNonReturnee('forward')(hash, uuid);
1330 return this;
134 },
135
136 /**
137 * Refresh the current page
138 *
139 * @method refresh
140 * @param {string} hash Unique hash of that fn call
141 * @param {string} uuid Unique hash of that fn call
142 * @chainable
143 */
144
145 refresh: function (hash, uuid) {
1460 this._createNonReturnee('refresh')(hash, uuid);
1470 return this;
148 }
149};
150
151/**
152 * Mixes in url methods
153 *
154 * @param {Dalek.DriverNative} DalekNative Native driver base class
155 * @return {Dalek.DriverNative} DalekNative Native driver base class
156 */
157
1581module.exports = function (DalekNative) {
159 // mixin methods
1600 Object.keys(Url).forEach(function (fn) {
1610 DalekNative.prototype[fn] = Url[fn];
162 });
163
1640 return DalekNative;
165};
166

/home/ubuntu/src/github.com/dalekjs/dalek-driver-native/lib/commands/window.js

11%
35
4
31
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');
29
30/**
31 * Window related methods
32 *
33 * @module Driver
34 * @class Window
35 * @namespace Dalek.DriverNative.Commands
36 */
37
381var Window = {
39
40 /**
41 * Switches to another window context
42 *
43 * @method toFrame
44 * @param {string} name Name of the window to switch to
45 * @param {string} hash Unique hash of that fn call
46 * @chainable
47 */
48
49 toWindow: function (name, hash) {
500 this.actionQueue.push(this.webdriverClient.windowHandles.bind(this.webdriverClient));
510 this.actionQueue.push(function (result) {
520 var deferred = Q.defer();
530 if (name === null) {
540 deferred.resolve(JSON.parse(result).value[0]);
55 }
560 deferred.resolve(name);
570 return deferred.promise;
58 });
590 this.actionQueue.push(this.webdriverClient.changeWindow.bind(this.webdriverClient));
600 this.actionQueue.push(this._windowCb.bind(this, name, hash));
610 return this;
62 },
63
64 /**
65 * Sends out an event with the results of the `toWindow` call
66 *
67 * @method _windowCb
68 * @param {string} name Name of the window to switch to
69 * @param {string} hash Unique hash of that fn call
70 * @param {string} result Serialized JSON with the reuslts of the toFrame call
71 * @return {object} promise Exists promise
72 * @private
73 */
74
75 _windowCb: function (name, hash) {
760 var deferred = Q.defer();
770 this.events.emit('driver:message', {key: 'toWindow', name: name, hash: hash, value: true});
780 deferred.resolve();
790 return deferred.promise;
80 },
81
82 /**
83 * Resizes the current window
84 *
85 * @method resize
86 * @param {object} dimensions New window width & height
87 * @param {string} hash Unique hash of that fn call
88 * @chainable
89 */
90
91 resize: function (dimensions, hash) {
920 this.actionQueue.push(this.webdriverClient.setWindowSize.bind(this.webdriverClient, dimensions.width, dimensions.height));
930 this.actionQueue.push(this._resizeCb.bind(this, dimensions, hash));
940 return this;
95 },
96
97 /**
98 * Sends out an event with the results of the `resize` call
99 *
100 * @method _windowCb
101 * @param {object} dimensions New window width & height
102 * @param {string} hash Unique hash of that fn call
103 * @param {string} result Serialized JSON with the reuslts of the toFrame call
104 * @return {object} promise Exists promise
105 * @private
106 */
107
108 _resizeCb: function (dimensions, hash) {
1090 var deferred = Q.defer();
1100 this.events.emit('driver:message', {key: 'resize', dimensions: dimensions, hash: hash, value: true});
1110 deferred.resolve();
1120 return deferred.promise;
113 },
114
115 /**
116 * Maximizes the current window
117 *
118 * @method maximize
119 * @param {string} hash Unique hash of that fn call
120 * @chainable
121 */
122
123 maximize: function (hash) {
1240 this.actionQueue.push(this.webdriverClient.maximize.bind(this.webdriverClient));
1250 this.actionQueue.push(this._maximizeCb.bind(this, hash));
1260 return this;
127 },
128
129 /**
130 * Sends out an event with the results of the `maximize` call
131 *
132 * @method _maximizeCb
133 * @param {string} hash Unique hash of that fn call
134 * @param {string} result Serialized JSON with the reuslts of the toFrame call
135 * @return {object} promise Exists promise
136 * @private
137 */
138
139 _maximizeCb: function (hash) {
1400 var deferred = Q.defer();
1410 this.events.emit('driver:message', {key: 'maximize', hash: hash, value: true});
1420 deferred.resolve();
1430 return deferred.promise;
144 }
145
146};
147
148/**
149 * Mixes in element methods
150 *
151 * @param {Dalek.DriverNative} DalekNative Native driver base class
152 * @return {Dalek.DriverNative} DalekNative Native driver base class
153 */
154
1551module.exports = function (DalekNative) {
156 // mixin methods
1570 Object.keys(Window).forEach(function (fn) {
1580 DalekNative.prototype[fn] = Window[fn];
159 });
160
1610 return DalekNative;
162};
163