forked from mozilla-b2g/gaia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
marionette.js
2656 lines (2324 loc) · 65.1 KB
/
marionette.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function() {
'use strict';
var isNode = typeof(window) === 'undefined';
if (!isNode) {
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
}
/**
* Constructor
*
* @param {Object} list of events to add onto responder.
*/
function Responder(events) {
this._$events = {};
if (typeof(events) !== 'undefined') {
this.addEventListener(events);
}
};
/**
* Stringifies request to websocket
*
*
* @param {String} command command name.
* @param {Object} data object to be sent over the wire.
* @return {String} json object.
*/
Responder.stringify = function stringify(command, data) {
return JSON.stringify([command, data]);
};
/**
* Parses request from WebSocket.
*
* @param {String} json json string to translate.
* @return {Object} ex: { event: 'test', data: {} }.
*/
Responder.parse = function parse(json) {
var data;
try {
data = (json.forEach) ? json : JSON.parse(json);
} catch (e) {
throw new Error("Could not parse json: '" + json + '"');
}
return {event: data[0], data: data[1]};
};
Responder.prototype = {
parse: Responder.parse,
stringify: Responder.stringify,
/**
* Events on this instance
*
* @type Object
*/
_$events: null,
/**
* Recieves json string event and dispatches an event.
*
* @param {String|Object} json data object to respond to.
* @param {String} json.event event to emit.
* @param {Object} json.data data to emit with event.
* @param {Object} [params] option number of params to pass to emit.
* @return {Object} result of WebSocketCommon.parse.
*/
respond: function respond(json) {
var event = Responder.parse(json),
args = Array.prototype.slice.call(arguments).slice(1);
args.unshift(event.data);
args.unshift(event.event);
this.emit.apply(this, args);
return event;
},
//TODO: Extract event emitter logic
/**
* Adds an event listener to this object.
*
*
* @param {String} type event name.
* @param {Function} callback event callback.
*/
addEventListener: function addEventListener(type, callback) {
var event;
if (typeof(callback) === 'undefined' && typeof(type) === 'object') {
for (event in type) {
if (type.hasOwnProperty(event)) {
this.addEventListener(event, type[event]);
}
}
return this;
}
if (!(type in this._$events)) {
this._$events[type] = [];
}
this._$events[type].push(callback);
return this;
},
/**
* Adds an event listener which will
* only fire once and then remove itself.
*
*
* @param {String} type event name.
* @param {Function} callback fired when event is emitted.
*/
once: function once(type, callback) {
var self = this;
function onceCb() {
self.removeEventListener(type, onceCb);
callback.apply(this, arguments);
}
this.addEventListener(type, onceCb);
return this;
},
/**
* Emits an event.
*
* Accepts any number of additional arguments to pass unto
* event listener.
*
* @param {String} eventName name of the event to emit.
* @param {Object} [arguments] additional arguments to pass.
*/
emit: function emit() {
var args = Array.prototype.slice.call(arguments),
event = args.shift(),
eventList,
self = this;
if (event in this._$events) {
eventList = this._$events[event];
eventList.forEach(function(callback) {
callback.apply(self, args);
});
}
return this;
},
/**
* Removes all event listeners for a given event type
*
*
* @param {String} event event type to remove.
*/
removeAllEventListeners: function removeAllEventListeners(name) {
if (name in this._$events) {
//reuse array
this._$events[name].length = 0;
}
return this;
},
/**
* Removes a single event listener from a given event type
* and callback function.
*
*
* @param {String} eventName event name.
* @param {Function} callback same instance of event handler.
*/
removeEventListener: function removeEventListener(name, callback) {
var i, length, events;
if (!(name in this._$events)) {
return false;
}
events = this._$events[name];
for (i = 0, length = events.length; i < length; i++) {
if (events[i] && events[i] === callback) {
events.splice(i, 1);
return true;
}
}
return false;
}
};
Responder.prototype.on = Responder.prototype.addEventListener;
if (isNode) {
module.exports = Responder;
} else {
window.TestAgent.Responder = Responder;
}
}());
//depends on TestAgent.Responder
(function() {
'use strict';
var isNode = typeof(window) === 'undefined',
Responder;
if (!isNode) {
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
Responder = TestAgent.Responder;
} else {
Responder = require('./responder');
}
//end
/**
* Creates a websocket client handles custom
* events via responders and auto-reconnect.
*
* Basic Options:
* - url: websocekt endpoint (for example: "ws://localhost:8888")
*
* Options for retries:
*
* @param {Object} options retry options.
* @param {Boolean} option.retry (false by default).
* @param {Numeric} option.retryLimit \
* ( number of retries before error is thrown Infinity by default).
* @param {Numeric} option.retryTimeout \
* ( Time between retries 3000ms by default).
*/
function Client(options) {
var key;
for (key in options) {
if (options.hasOwnProperty(key)) {
this[key] = options[key];
}
}
Responder.call(this);
this.proxyEvents = ['open', 'close', 'message'];
this._proxiedEvents = {};
if (isNode) {
this.Native = require('ws');
} else {
this.Native = (window.WebSocket || window.MozWebSocket);
}
this.on('open', this._setConnectionStatus.bind(this, true));
this.on('close', this._setConnectionStatus.bind(this, false));
this.on('close', this._incrementRetry.bind(this));
this.on('message', this._processMessage.bind(this));
this.on('open', this._clearRetries.bind(this));
};
Client.RetryError = function RetryError() {
Error.apply(this, arguments);
};
Client.RetryError.prototype = Object.create(Error.prototype);
Client.prototype = Object.create(Responder.prototype);
/**
* True when connection is opened.
* Used to ensure messages are not sent
* when connection to server is closed.
*
* @type Boolean
*/
Client.prototype.connectionOpen = false;
//Retry
Client.prototype.retry = false;
Client.prototype.retries = 0;
Client.prototype.retryLimit = Infinity;
Client.prototype.retryTimeout = 3000;
Client.prototype.start = function start() {
var i, event, fn;
if (this.socket && this.socket.readyState < 2) {
// don't open a socket is one is already open.
return;
}
if (this.retry && this.retries >= this.retryLimit) {
throw new Client.RetryError(
'Retry limit has been reach retried ' + String(this.retries) + ' times'
);
}
if (this.socket) {
this.close();
}
this.socket = new this.Native(this.url);
for (i = 0; i < this.proxyEvents.length; i++) {
event = this.proxyEvents[i];
fn = this._proxiedEvents[event] = this._proxyEvent.bind(this, event);
this.socket.addEventListener(event, fn, false);
}
this.emit('start', this);
};
/**
* Sends Responder encoded event to the server.
*
* @param {String} event event to send.
* @param {String} data object to send to the server.
*/
Client.prototype.send = function send(event, data) {
if (this.connectionOpen) {
this.socket.send(this.stringify(event, data));
}
};
/**
* Closes connection to the server
*/
Client.prototype.close = function close(event, data) {
var event;
for (event in this._proxiedEvents) {
this.socket.removeEventListener(event, this._proxiedEvents[event], false);
}
this.socket.close();
};
Client.prototype._incrementRetry = function _incrementRetry() {
if (this.retry) {
this.retries++;
setTimeout(this.start.bind(this), this.retryTimeout);
}
};
Client.prototype._processMessage = function _processMessage(message) {
if (message.data) {
message = message.data;
}
this.respond(message, this);
};
Client.prototype._clearRetries = function _clearRetries() {
this.retries = 0;
};
Client.prototype._proxyEvent = function _proxyEvent() {
this.emit.apply(this, arguments);
};
/**
* Sets connectionOpen.
*
* @param {Boolean} type connection status.
*/
Client.prototype._setConnectionStatus = _setConnectionStatus;
function _setConnectionStatus(type) {
this.connectionOpen = type;
}
if (isNode) {
module.exports = Client;
} else {
window.TestAgent.WebsocketClient = Client;
}
}());
(function(global, module) {
/**
* Define a list of paths
* this will only be used in the browser.
*/
var paths = {};
/**
* Exports object is a shim
* we use in the browser to
* create an object that will behave much
* like module.exports
*/
function Exports(path) {
this.path = path;
}
Exports.prototype = {
/**
* Unified require between browser/node.
* Path is relative to this file so you
* will want to use it like this from any depth.
*
*
* var Leaf = ns.require('sub/leaf');
*
*
* @param {String} path path lookup relative to this file.
*/
require: function exportRequire(path) {
if (typeof(window) === 'undefined') {
return require(require('path').join(__dirname, path));
} else {
return paths[path];
}
},
/**
* Maps exports to a file path.
*/
set exports(val) {
return paths[this.path] = val;
},
get exports() {
return paths[this.path];
}
};
/**
* Module object constructor.
*
*
* var module = Module('sub/leaf');
* module.exports = function Leaf(){}
*
*
* @constructor
* @param {String} path file path.
*/
function Module(path) {
return new Exports(path);
}
Module.require = Exports.prototype.require;
Module.exports = Module;
Module._paths = paths;
/**
* Reference self as exports
* which also happens to be the constructor
* so you can assign items to the namespace:
*
* //assign to Module.X
* //assume module.exports is Module
* module.exports.X = Foo; //Module.X === Foo;
* Module.exports('foo'); //creates module.exports object.
*
*/
module.exports = Module;
/**
* In the browser assign
* to a global namespace
* obviously 'Module' would
* be whatever your global namespace is.
*/
if (this.window)
window.Marionette = Module;
}(
this,
(typeof(module) === 'undefined') ?
{} :
module
));
(function(module, ns) {
var code, errorCodes, Err = {};
Err.codes = errorCodes = {
7: 'NoSuchElement',
8: 'NoSuchFrame',
9: 'UnknownCommand',
10: 'StaleElementReference',
11: 'ElementNotVisible',
12: 'InvalidElementState',
13: 'UnknownError',
15: 'ElementIsNotSelectable',
17: 'JavaScriptError',
19: 'XPathLookupError',
21: 'Timeout',
23: 'NoSuchWindow',
24: 'InvalidCookieDomain',
25: 'UnableToSetCookie',
26: 'UnexpectedAlertOpen',
27: 'NoAlertOpenError',
28: 'ScriptTimeout',
29: 'InvalidElementCoordinates',
30: 'IMENotAvailable',
31: 'IMEEngineActivationFailed',
32: 'InvalidSelector',
500: 'GenericError'
};
Err.Exception = Error;
//used over Object.create intentionally
Err.Exception.prototype = new Error();
for (code in errorCodes) {
(function(code) {
Err[errorCodes[code]] = function(obj) {
var message = '',
err = new Error();
if (obj.status) {
message += '(' + obj.status + ') ';
}
message += (obj.message || '');
message += '\nRemote Stack:\n';
message += obj.stacktrace || '<none>';
this.message = message;
this.type = errorCodes[code];
this.name = this.type;
this.fileName = err.fileName;
this.lineNumber = err.lineNumber;
if (err.stack) {
// remove one stack level:
if (typeof(Components) != 'undefined') {
// Mozilla:
this.stack = err.stack.substring(err.stack.indexOf('\n') + 1);
} else if ((typeof(chrome) != 'undefined') ||
(typeof(process) != 'undefined')) {
// Google Chrome/Node.js:
this.stack = err.stack.replace(/\n[^\n]*/, '');
} else {
this.stack = err.stack;
}
}
}
Err[errorCodes[code]].prototype = new Err.Exception();
}(code));
}
/**
* Returns an error object given
* a error object from the marionette client.
* Expected input follows this format:
*
* Codes are from:
* http://code.google.com/p/selenium/wiki/JsonWireProtocol#Response_Status_Codes
*
* {
* message: "Something",
* stacktrace: "wentwrong@line",
* status: 17
* }
*
* @param {Object} obj remote error object.
*/
Err.error = function exception(obj) {
if (obj instanceof Err.Exception) {
return obj;
}
if (obj.status in errorCodes) {
return new Err[errorCodes[obj.status]](obj);
} else {
if (obj.message || obj.stacktrace) {
return new Err.GenericError(obj);
}
return obj;
}
}
module.exports = Err;
}.apply(
this,
(this.Marionette) ?
[Marionette('error'), Marionette] :
[module, require('./marionette')]
));
/**
@namespace
*/
(function(module, ns) {
var Native;
if (typeof(window) === 'undefined') {
Native = require('../XMLHttpRequest').XMLHttpRequest;
} else {
Native = window.XMLHttpRequest;
}
/**
* Creates a XHR wrapper.
* Depending on the platform this is loaded
* from the correct wrapper type will be used.
*
* Options are derived from properties on the prototype.
* See each property for its default value.
*
* @class
* @name Marionette.Xhr
* @param {Object} options options for xhr.
* @param {String} [options.method="GET"] any HTTP verb like 'GET' or 'POST'.
* @param {Boolean} [options.async] false will indicate
* a synchronous request.
* @param {Object} [options.headers] full of http headers.
* @param {Object} [options.data] post data.
*/
function Xhr(options) {
var key;
if (typeof(options) === 'undefined') {
options = {};
}
for (key in options) {
if (options.hasOwnProperty(key)) {
this[key] = options[key];
}
}
}
Xhr.prototype = {
/** @scope Marionette.Xhr.prototype */
xhrClass: Native,
method: 'GET',
async: true,
waiting: false,
headers: {
'Content-Type': 'application/json'
},
data: {},
_seralize: function _seralize() {
if (this.headers['Content-Type'] === 'application/json') {
return JSON.stringify(this.data);
}
return this.data;
},
/**
* Aborts request if its in progress.
*/
abort: function abort() {
if (this.xhr) {
this.xhr.abort();
}
},
/**
* Sends request to server.
*
* @param {Function} callback success/failure handler.
*/
send: function send(callback) {
var header, xhr;
if (typeof(callback) === 'undefined') {
callback = this.callback;
}
xhr = this.xhr = new this.xhrClass();
xhr.open(this.method, this.url, this.async);
for (header in this.headers) {
if (this.headers.hasOwnProperty(header)) {
xhr.setRequestHeader(header, this.headers[header]);
}
}
xhr.onreadystatechange = function onReadyStateChange() {
var data, type;
if (xhr.readyState === 4) {
data = xhr.responseText;
type = xhr.getResponseHeader('content-type');
type = type || xhr.getResponseHeader('Content-Type');
if (type === 'application/json') {
data = JSON.parse(data);
}
this.waiting = false;
callback(data, xhr);
}
}.bind(this);
this.waiting = true;
xhr.send(this._seralize());
}
};
module.exports = Xhr;
}.apply(
this,
(this.Marionette) ?
[Marionette('xhr'), Marionette] :
[module, require('./marionette')]
));
(function(module, ns) {
var debug = function() {},
Responder;
var isNode = typeof(window) === 'undefined';
var isXpc = !isNode && (typeof(window.xpcModule) !== 'undefined');
if (isNode) {
debug = require('debug')('marionette:command-stream');
Responder = require('test-agent/lib/test-agent/responder');
} else {
Responder = TestAgent.Responder;
}
if (isXpc) {
debug = window.xpcModule.require('debug')('marionette:command-stream');
}
/**
* Command stream accepts a socket or any event
* emitter that will emit data events
*
* @class Marionette.CommandStream
* @param {EventEmitter} socket socket instance.
* @constructor
*/
function CommandStream(socket) {
this.buffer = '';
this.inCommand = false;
this.commandLength = 0;
this.socket = socket;
Responder.apply(this);
socket.on('data', this.add.bind(this));
socket.on('error', function() {
console.log(arguments);
});
}
var proto = CommandStream.prototype = Object.create(
Responder.prototype
);
/**
* Length prefix
*
* @property prefix
* @type String
*/
proto.prefix = ':';
/**
* name of the event this class
* will emit when a response to a
* command is received.
*
* @property commandEvent
* @type String
*/
proto.commandEvent = 'command';
/**
* Parses command into a string to
* be sent over a tcp socket to marionette.
*
*
* @method stringify
* @param {Object} command marionette command.
* @return {String} command as a string.
*/
proto.stringify = function stringify(command) {
var string;
if (typeof(command) === 'string') {
string = command;
} else {
string = JSON.stringify(command);
}
return String(string.length) + this.prefix + string;
};
/**
* Accepts raw string command parses it and
* emits a commandEvent.
*
* @private
* @method _handleCommand
* @param {String} string raw response from marionette.
*/
proto._handleCommand = function _handleCommand(string) {
debug('got raw bytes ', string);
var data = JSON.parse(string);
debug('sending event', data);
this.emit(this.commandEvent, data);
};
/**
* Checks if current buffer is ready to read.
*
* @private
* @method _checkBuffer
* @return {Boolean} true when in a command and buffer \
* is ready to begin reading.
*/
proto._checkBuffer = function _checkBuffer() {
var lengthIndex;
if (!this.inCommand) {
lengthIndex = this.buffer.indexOf(this.prefix);
if (lengthIndex !== -1) {
this.commandLength = parseInt(this.buffer.slice(0, lengthIndex));
this.buffer = this.buffer.slice(lengthIndex + 1);
this.inCommand = true;
}
}
return this.inCommand;
};
/**
* Read current buffer.
* Drain and emit all comands from the buffer.
*
* @method _readBuffer
* @private
* @return {Object} self.
*/
proto._readBuffer = function _readBuffer() {
var commandString;
if (this._checkBuffer()) {
if (this.buffer.length >= this.commandLength) {
commandString = this.buffer.slice(0, this.commandLength);
this._handleCommand(commandString);
this.buffer = this.buffer.slice(this.commandLength);
this.inCommand = false;
this._readBuffer();
}
}
return this;
};
/**
* Writes a command to the socket.
* Handles conversion and formatting of object.
*
* @method send
* @param {Object} data marionette command.
*/
proto.send = function send(data) {
debug('writing ', data, 'to socket');
if (this.socket.write) {
//nodejs socket
this.socket.write(this.stringify(data), 'utf8');
} else {
//moztcp socket
this.socket.send(this.stringify(data));
}
};
/**
* Adds a chunk (string or buffer) to the
* total buffer of this instance.
*
* @this
* @param {String|Buffer} buffer buffer or string to add.
*/
proto.add = function add(buffer) {
var lengthIndex, command;
this.buffer += buffer.toString();
this._readBuffer();
};
module.exports = exports = CommandStream;
}.apply(
this,
(this.Marionette) ?
[Marionette('command-stream'), Marionette] :
[module, require('./marionette')]
));
/**
@namespace
*/
(function(module, ns) {
/**
* Creates an element reference
* based on an id and a client instance.
* You should never need to manually create
* an instance of element.
*
* Use {{#crossLink "Marionette.Client/findElement"}}{{/crossLink}} or
* {{#crossLink "Marionette.Client/findElements"}}{{/crossLink}} to create
* instance(s) of this class.
*
* @class Marionette.Element
* @param {String} id id of element.
* @param {Marionette.Client} client client instance.
*/
function Element(id, client) {
this.id = id;
this.client = client;
}
Element.prototype = {
/**
* Sends remote command processes the result.
* Appends element id to each command.
*
* @method _sendCommand
* @chainable
* @private
* @param {Object} command marionette request.
* @param {String} responseKey key in the response to pass to callback.
* @param {Function} callback callback function receives the result of
* response[responseKey] as its first argument.
*
* @return {Object} self.
*/
_sendCommand: function(command, responseKey, callback) {
if (!command.element) {
command.element = this.id;
}
this.client._sendCommand(command, responseKey, callback);
return this;
},
/**
* Finds a single child of this element.
*
* @method findElement
* @param {String} query search string.
* @param {String} method search method.
* @param {Function} callback element callback.
* @return {Object} self.
*/
findElement: function findElement(query, method, callback) {
this.client.findElement(query, method, this.id, callback);
return this;
},
/**
* Finds a all children of this element that match a pattern.
*
* @method findElements
* @param {String} query search string.
* @param {String} method search method.
* @param {Function} callback element callback.
* @return {Object} self.
*/
findElements: function findElement(query, method, callback) {
this.client.findElements(query, method, this.id, callback);
return this;
},
/**
* Shortcut method to execute
* a function with this element as first argument.
*
*
* @method scriptWith
* @param {Function|String} script remote script.
* @param {Function} callback callback when script completes.
*/
scriptWith: function scriptWith(script, callback) {
this.client.executeScript(script, [this], callback);
},
/**
* Checks to see if two elements are equal
*
* @method equals