protractor_spec.js
function(done, fail, tries) {
    // The default retrial policy.
    if (typeof tries === 'undefined') {
      tries = FLAKY_TEST_RETRIAL;
    }
    // executeScript runs the passed method in the "window" context of
    // the current test. JSUnit exposes hooks into the test's status through
    // the "G_testRunner" global object.
    browser.executeScript(function() {
      if (window['G_testRunner'] && window['G_testRunner']['isFinished']()) {
        return {
          isFinished: true,
          isSuccess: window['G_testRunner']['isSuccess'](),
          report: window['G_testRunner']['getReport']()
        };
      } else {
        return {'isFinished': false};
      }
    }).then(function(status) {
      // Tests completed on the page but something failed. Retry a certain
      // number of times in case of flakiness.
      if (status && status.isFinished && !status.isSuccess && tries > 1) {
        // Try again in a few ms.
        setTimeout(waitForTest.bind(undefined, done, fail, tries - 1), 300);
      } else if (status && status.isFinished) {
        done(status);
      } else {
        // Try again in a few ms.
        setTimeout(waitForTest.bind(undefined, done, fail, tries), 300);
      }
    }, function(err) {
      // This can happen if the webdriver had an issue executing the script.
      fail(err);
    });
  }
function(done, fail, tries) {
    // The default retrial policy.
    if (typeof tries === 'undefined') {
      tries = FLAKY_TEST_RETRIAL;
    }
    // executeScript runs the passed method in the "window" context of
    // the current test. JSUnit exposes hooks into the test's status through
    // the "G_testRunner" global object.
    browser.executeScript(function() {
      if (window['G_testRunner'] && window['G_testRunner']['isFinished']()) {
        return {
          isFinished: true,
          isSuccess: window['G_testRunner']['isSuccess'](),
          report: window['G_testRunner']['getReport']()
        };
      } else {
        return {'isFinished': false};
      }
    }).then(function(status) {
      // Tests completed on the page but something failed. Retry a certain
      // number of times in case of flakiness.
      if (status && status.isFinished && !status.isSuccess && tries > 1) {
        // Try again in a few ms.
        setTimeout(waitForTest.bind(undefined, done, fail, tries - 1), 300);
      } else if (status && status.isFinished) {
        done(status);
      } else {
        // Try again in a few ms.
        setTimeout(waitForTest.bind(undefined, done, fail, tries), 300);
      }
    }, function(err) {
      // This can happen if the webdriver had an issue executing the script.
      fail(err);
    });
  }
function ( done , fail , tries ) { // The default retrial policy. if ( typeof tries === 'undefined' ) { tries = FLAKY_TEST_RETRIAL ; } // executeScript runs the passed method in the "window" context of // the current test. JSUnit exposes hooks into the test's status through // the "G_testRunner" global object. browser . executeScript ( function ( ) { if ( window [ 'G_testRunner' ] && window [ 'G_testRunner' ] [ 'isFinished' ] ( ) ) { return { isFinished : true , isSuccess : window [ 'G_testRunner' ] [ 'isSuccess' ] ( ) , report : window [ 'G_testRunner' ] [ 'getReport' ] ( ) } ; } else { return { 'isFinished' : false } ; } } ) . then ( function ( status ) { // Tests completed on the page but something failed. Retry a certain // number of times in case of flakiness. if ( status && status . isFinished && ! status . isSuccess && tries > 1 ) { // Try again in a few ms. setTimeout ( waitForTest . bind ( undefined , done , fail , tries - 1 ) , 300 ) ; } else if ( status && status . isFinished ) { done ( status ) ; } else { // Try again in a few ms. setTimeout ( waitForTest . bind ( undefined , done , fail , tries ) , 300 ) ; } } , function ( err ) { // This can happen if the webdriver had an issue executing the script. fail ( err ) ; } ) ; }
Waits for current tests to be executed.
@param {!Object} done The function called when the test is finished.
@param {!Error} fail The function called when an unrecoverable error
happened during the test.
@param {?number=} tries The number of trials so far for the current test.
This is used to retry flaky tests.
Waits for current tests to be executed .