index.js
function initJasmineWd(scheduler, webdriver) {
  if (jasmine.JasmineWdInitialized) {
    throw Error('JasmineWd already initialized when init() was called');
  }
  jasmine.JasmineWdInitialized = true;


  // Pull information from webdriver instance
  if (webdriver) {
    WebElement = webdriver.WebElement || WebElement;
    idleEventName = (
            webdriver.promise &&
            webdriver.promise.ControlFlow &&
            webdriver.promise.ControlFlow.EventType &&
            webdriver.promise.ControlFlow.EventType.IDLE
        ) || idleEventname;
  }

  // Default to mock scheduler
  if (!scheduler) {
    scheduler = { execute: function(fn) {
      return Promise.resolve().then(fn);
    } };
  }

  // Figure out how we're getting new promises
  var newPromise;
  if (typeof scheduler.promise == 'function') {
    newPromise = scheduler.promise.bind(scheduler);
  } else if (webdriver && webdriver.promise && webdriver.promise.ControlFlow &&
      (scheduler instanceof webdriver.promise.ControlFlow) &&
      (webdriver.promise.USE_PROMISE_MANAGER !== false)) {
    newPromise = function(resolver) {
      return new webdriver.promise.Promise(resolver, scheduler);
    };
  } else {
    newPromise = function(resolver) {
      return new Promise(resolver);
    };
  }

  // Wrap functions
  global.it = wrapInScheduler(scheduler, newPromise, global.it, 'it');
  global.fit = wrapInScheduler(scheduler, newPromise, global.fit, 'fit');
  global.beforeEach = wrapInScheduler(scheduler, newPromise, global.beforeEach, 'beforeEach');
  global.afterEach = wrapInScheduler(scheduler, newPromise, global.afterEach, 'afterEach');
  global.beforeAll = wrapInScheduler(scheduler, newPromise, global.beforeAll, 'beforeAll');
  global.afterAll = wrapInScheduler(scheduler, newPromise, global.afterAll, 'afterAll');

  // Reset API
  if (scheduler.reset) {
    // On timeout, the flow should be reset. This will prevent webdriver tasks
    // from overflowing into the next test and causing it to fail or timeout
    // as well. This is done in the reporter instead of an afterEach block
    // to ensure that it runs after any afterEach() blocks with webdriver tasks
    // get to complete first.
    jasmine.getEnv().addReporter(new OnTimeoutReporter(function() {
      console.warn('A Jasmine spec timed out. Resetting the WebDriver Control Flow.');
      scheduler.reset();
    }));
  }
}
function initJasmineWd(scheduler, webdriver) {
  if (jasmine.JasmineWdInitialized) {
    throw Error('JasmineWd already initialized when init() was called');
  }
  jasmine.JasmineWdInitialized = true;


  // Pull information from webdriver instance
  if (webdriver) {
    WebElement = webdriver.WebElement || WebElement;
    idleEventName = (
            webdriver.promise &&
            webdriver.promise.ControlFlow &&
            webdriver.promise.ControlFlow.EventType &&
            webdriver.promise.ControlFlow.EventType.IDLE
        ) || idleEventname;
  }

  // Default to mock scheduler
  if (!scheduler) {
    scheduler = { execute: function(fn) {
      return Promise.resolve().then(fn);
    } };
  }

  // Figure out how we're getting new promises
  var newPromise;
  if (typeof scheduler.promise == 'function') {
    newPromise = scheduler.promise.bind(scheduler);
  } else if (webdriver && webdriver.promise && webdriver.promise.ControlFlow &&
      (scheduler instanceof webdriver.promise.ControlFlow) &&
      (webdriver.promise.USE_PROMISE_MANAGER !== false)) {
    newPromise = function(resolver) {
      return new webdriver.promise.Promise(resolver, scheduler);
    };
  } else {
    newPromise = function(resolver) {
      return new Promise(resolver);
    };
  }

  // Wrap functions
  global.it = wrapInScheduler(scheduler, newPromise, global.it, 'it');
  global.fit = wrapInScheduler(scheduler, newPromise, global.fit, 'fit');
  global.beforeEach = wrapInScheduler(scheduler, newPromise, global.beforeEach, 'beforeEach');
  global.afterEach = wrapInScheduler(scheduler, newPromise, global.afterEach, 'afterEach');
  global.beforeAll = wrapInScheduler(scheduler, newPromise, global.beforeAll, 'beforeAll');
  global.afterAll = wrapInScheduler(scheduler, newPromise, global.afterAll, 'afterAll');

  // Reset API
  if (scheduler.reset) {
    // On timeout, the flow should be reset. This will prevent webdriver tasks
    // from overflowing into the next test and causing it to fail or timeout
    // as well. This is done in the reporter instead of an afterEach block
    // to ensure that it runs after any afterEach() blocks with webdriver tasks
    // get to complete first.
    jasmine.getEnv().addReporter(new OnTimeoutReporter(function() {
      console.warn('A Jasmine spec timed out. Resetting the WebDriver Control Flow.');
      scheduler.reset();
    }));
  }
}
function initJasmineWd ( scheduler , webdriver ) { if ( jasmine . JasmineWdInitialized ) { throw Error ( 'JasmineWd already initialized when init() was called' ) ; } jasmine . JasmineWdInitialized = true ; // Pull information from webdriver instance if ( webdriver ) { WebElement = webdriver . WebElement || WebElement ; idleEventName = ( webdriver . promise && webdriver . promise . ControlFlow && webdriver . promise . ControlFlow . EventType && webdriver . promise . ControlFlow . EventType . IDLE ) || idleEventname ; } // Default to mock scheduler if ( ! scheduler ) { scheduler = { execute : function ( fn ) { return Promise . resolve ( ) . then ( fn ) ; } } ; } // Figure out how we're getting new promises var newPromise ; if ( typeof scheduler . promise == 'function' ) { newPromise = scheduler . promise . bind ( scheduler ) ; } else if ( webdriver && webdriver . promise && webdriver . promise . ControlFlow && ( scheduler instanceof webdriver . promise . ControlFlow ) && ( webdriver . promise . USE_PROMISE_MANAGER !== false ) ) { newPromise = function ( resolver ) { return new webdriver . promise . Promise ( resolver , scheduler ) ; } ; } else { newPromise = function ( resolver ) { return new Promise ( resolver ) ; } ; } // Wrap functions global . it = wrapInScheduler ( scheduler , newPromise , global . it , 'it' ) ; global . fit = wrapInScheduler ( scheduler , newPromise , global . fit , 'fit' ) ; global . beforeEach = wrapInScheduler ( scheduler , newPromise , global . beforeEach , 'beforeEach' ) ; global . afterEach = wrapInScheduler ( scheduler , newPromise , global . afterEach , 'afterEach' ) ; global . beforeAll = wrapInScheduler ( scheduler , newPromise , global . beforeAll , 'beforeAll' ) ; global . afterAll = wrapInScheduler ( scheduler , newPromise , global . afterAll , 'afterAll' ) ; // Reset API if ( scheduler . reset ) { // On timeout, the flow should be reset. This will prevent webdriver tasks // from overflowing into the next test and causing it to fail or timeout // as well. This is done in the reporter instead of an afterEach block // to ensure that it runs after any afterEach() blocks with webdriver tasks // get to complete first. jasmine . getEnv ( ) . addReporter ( new OnTimeoutReporter ( function ( ) { console . warn ( 'A Jasmine spec timed out. Resetting the WebDriver Control Flow.' ) ; scheduler . reset ( ) ; } ) ) ; } }
Initialize the JasmineWd adapter with a particlar scheduler, generally a webdriver control flow.

@param {Object=} scheduler The scheduler to wrap tests in. See scheduler.md for details.
Defaults to a mock scheduler that calls functions immediately.
@param {Object=} webdriver The result of `require('selenium-webdriver')`.  Passed in here rather
than required by jasminewd directly so that jasminewd can't end up up with a different version
of `selenium-webdriver` than your tests use.  If not specified, jasminewd will still work, but
it won't check for `WebElement` instances in expect() statements and could cause control flow
problems if your tests are using an old version of `selenium-webdriver` (e.g. version 2.53.0).
Initialize the JasmineWd adapter with a particlar scheduler generally a webdriver control flow .