pause.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. var util = require('util');
  2. var events = require('events');
  3. /**
  4. * Suspends the test for the given time in milliseconds. If the milliseconds argument is missing it will suspend the test indefinitely
  5. *
  6. * ```
  7. * this.demoTest = function (browser) {
  8. * browser.pause(1000);
  9. * // or suspend indefinitely
  10. * browser.pause();
  11. * };
  12. * ```
  13. *
  14. * @method pause
  15. * @param {number} ms The number of milliseconds to wait.
  16. * @param {function} [callback] Optional callback function to be called when the command finishes.
  17. * @api commands
  18. */
  19. function Pause() {
  20. events.EventEmitter.call(this);
  21. }
  22. util.inherits(Pause, events.EventEmitter);
  23. Pause.prototype.command = function(ms, cb) {
  24. var self = this;
  25. // If we don't pass the milliseconds, the client will
  26. // be suspended indefinitely
  27. if (!ms) {
  28. return this;
  29. }
  30. setTimeout(function() {
  31. // if we have a callback, call it right before the complete event
  32. if (cb) {
  33. cb.call(self.client.api);
  34. }
  35. self.emit('complete');
  36. }, ms);
  37. return this;
  38. };
  39. module.exports = Pause;