pause.js
1.03 KB
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
var util = require('util');
var events = require('events');
/**
* Suspends the test for the given time in milliseconds. If the milliseconds argument is missing it will suspend the test indefinitely
*
* ```
* this.demoTest = function (browser) {
* browser.pause(1000);
* // or suspend indefinitely
* browser.pause();
* };
* ```
*
* @method pause
* @param {number} ms The number of milliseconds to wait.
* @param {function} [callback] Optional callback function to be called when the command finishes.
* @api commands
*/
function Pause() {
events.EventEmitter.call(this);
}
util.inherits(Pause, events.EventEmitter);
Pause.prototype.command = function(ms, cb) {
var self = this;
// If we don't pass the milliseconds, the client will
// be suspended indefinitely
if (!ms) {
return this;
}
setTimeout(function() {
// if we have a callback, call it right before the complete event
if (cb) {
cb.call(self.client.api);
}
self.emit('complete');
}, ms);
return this;
};
module.exports = Pause;