code: function(testPath) {
      var testStartTime = +new Date();
  
      var waitForTest = function(resolve, reject) {
        // 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']()) {
                var status = {};
                status['isFinished'] = true;
                status['isSuccess'] = window['G_testRunner']['isSuccess']();
                status['report'] = window['G_testRunner']['getReport']();
                return status;
              } else {
                return {'isFinished': false};
              }
            })
            .then(
                function(status) {
                  if (status && status.isFinished) {
                    resolve(status);
                  } else {
                    var currTime = +new Date();
                    if (currTime - testStartTime > TEST_TIMEOUT) {
                      status.isSuccess = false;
                      status.report = testPath + ' timed out after ' +
                          (TEST_TIMEOUT / 1000) + 's!';
                      // resolve so tests continue running.
                      resolve(status);
                    } else {
                      // Check every 300ms for completion.
                      setTimeout(
                          waitForTest.bind(undefined, resolve, reject), 300);
                    }
                  }
                },
                function(err) {
                  reject(err);
                });
      };
  
      return new Promise(function(resolve, reject) {
        waitForTest(resolve, reject);
      });
    }
docs: Polls currently loaded test page for test completion. Returns Promise that will resolve when test is finished.