constructor: function(obj, msg, stack) {
			var wrappedObj = obj
			if ( ! webdriver.promise.isPromise(obj)) {
		
				wrappedObj = browser.driver.controlFlow().execute(function() {return actual;});
			}
			OrigAssertion.prototype.constructor.call(this, wrappedObj, msg, stack);
		}
Example #2
0
 function defaultNegativeCompare() {
   var result = matcher.compare.apply(null, args);
   if (webdriver.promise.isPromise(result.pass)) {
     result.pass = result.pass.then(function(pass) {
       return !pass;
     });
   } else {
     result.pass = !result.pass;
   }
   return result;
 }
Example #3
0
  flow.execute(function() {
    try {
      result = vm.runInThisContext(code, file);
    } catch (e) {
      vmErr = e;
      callback(vmErr, null);
    }
    if (vmErr && process.domain) {
      process.domain.emit('error', vmErr);
      process.domain.exit();
    }

    if (webdriver.promise.isPromise(result)) {
      return result.then(function(val) {return val});
    } else {
      return result;
    }
  }).then(function(res) {
Example #4
0
 var execFn_ = function () {
     // Run code through vm so that we can maintain a local scope which is
     // isolated from the rest of the execution.
     var res = vm_.runInContext(code, sandbox);
     if (!selenium_webdriver_1.promise.isPromise(res)) {
         res = selenium_webdriver_1.promise.fulfilled(res);
     }
     return res.then(function (res) {
         if (res === undefined) {
             return undefined;
         }
         else {
             // The '' forces res to be expanded into a string instead of just
             // '[Object]'. Then we remove the extra space caused by the ''
             // using substring.
             return util.format.apply(_this, ['', res]).substring(1);
         }
     });
 };
Example #5
0
/**
 * Calls a function from a plugin safely.  If the plugin's function throws an
 * exception or returns a rejected promise, that failure will be logged as a
 * failed test result instead of crashing protractor.  If the tests results have
 * already been reported, the failure will be logged to the console.
 *
 * @param {Object} pluginObj The plugin object containing the function to be run
 * @param {string} funName The name of the function we want to run
 * @param {*[]} args The arguments we want to invoke the function with
 * @param {PROMISE_TYPE} promiseType The type of promise (WebDriver or Q) that
 *    should be used
 * @param {boolean} resultsReported If the results have already been reported
 * @param {*} failReturnVal The value to return if the function fails
 *
 * @return {webdriver.promise.Promise} A promise which resolves to the
 *     function's return value
 */
function safeCallPluginFun(pluginObj, funName, args, promiseType,
    resultsReported, failReturnVal) {
  var deferred = promiseType == PROMISE_TYPE.Q ? q.defer() :
      webdriver.promise.defer();
  var logError = function(e) {
    if (resultsReported) {
      printPluginResults([{
        description: pluginObj.name + ' Runtime',
        assertions: [{
          passed: false,
          errorMsg: 'Failure during ' + funName + ': ' + (e.message || e),
          stackTrace: e.stack
        }]
      }]);
    } else {
        pluginObj.addFailure('Failure during ' + funName + ': ' +
            e.message || e, {stackTrace: e.stack});
    }
    deferred.fulfill(failReturnVal);
  };
  try {
    var result = pluginObj[funName].apply(pluginObj, args);
    if (webdriver.promise.isPromise(result)) {
      result.then(function() {
        deferred.fulfill.apply(deferred, arguments);
      }, function(e) {
        logError(e);
      });
    } else {
      deferred.fulfill(result);
    }
  } catch(e) {
    logError(e);
  }
  return deferred.promise;
}
Example #6
0
  return function() {
    var expected = Array.prototype.slice.call(arguments, 0),
      expectation = this,
      matchError = new Error("Failed expectation");

    matchError.stack = matchError.stack.replace(/ +at.+jasminewd.+\n/, '');

    if (!webdriver.promise.isPromise(expectation.actual) &&
        !webdriver.promise.isPromise(expected)) {
      originalWrapCompare(name, matcherFactory).apply(this, arguments);
    } else {
      webdriver.promise.when(expectation.actual).then(function(actual) {
        return webdriver.promise.all(expected).then(function(expected) {
          return compare(actual, expected);
        });
      });
    }

    function compare(actual, expected) {
      var args = expected.slice(0);
      args.unshift(actual);

      var matcher = matcherFactory(expectation.util, expectation.customEqualityTesters);
      var matcherCompare = matcher.compare;

      if (expectation.isNot) {
        matcherCompare = matcher.negativeCompare || defaultNegativeCompare;
      }

      var result = matcherCompare.apply(null, args);

      return webdriver.promise.when(result.pass).then(function(pass) {
        var message = '';

        if (!pass) {
          if (!result.message) {
            args.unshift(expectation.isNot);
            args.unshift(name);
            message = expectation.util.buildFailureMessage.apply(null, args);
          } else {
            if (Object.prototype.toString.apply(result.message) === '[object Function]') {
              message = result.message();
            } else {
              message = result.message;
            }
          }
        }

        if (expected.length == 1) {
          expected = expected[0];
        }
        var res = {
          matcherName: name,
          passed: pass,
          message: message,
          actual: actual,
          expected: expected,
          error: matchError
        };
        expectation.addExpectationResult(pass, res);
      });

      function defaultNegativeCompare() {
        var result = matcher.compare.apply(null, args);
        if (webdriver.promise.isPromise(result.pass)) {
          result.pass = result.pass.then(function(pass) {
            return !pass;
          });
        } else {
          result.pass = !result.pass;
        }
        return result;
      }
    }
  };
Example #7
0
    function compare(actual, expected) {
      var args = expected.slice(0);
      args.unshift(actual);

      var matcher = matcherFactory(expectation.util, expectation.customEqualityTesters);
      var matcherCompare = matcher.compare;

      if (expectation.isNot) {
        matcherCompare = matcher.negativeCompare || defaultNegativeCompare;
      }

      var result = matcherCompare.apply(null, args);

      if (webdriver.promise.isPromise(result.pass)) {
       return webdriver.promise.when(result.pass).then(compareDone);
      } else {
       return compareDone(result.pass);
      }

      function compareDone(pass) {
       var message = '';

       if (!pass) {
        if (!result.message) {
         args.unshift(expectation.isNot);
         args.unshift(name);
         message = expectation.util.buildFailureMessage.apply(null, args);
        } else {
         if (Object.prototype.toString.apply(result.message) === '[object Function]') {
          message = result.message();
         } else {
          message = result.message;
         }
        }
       }

       if (expected.length == 1) {
        expected = expected[0];
       }
       var res = {
        matcherName: name,
        passed: pass,
        message: message,
        actual: actual,
        expected: expected,
        error: matchError
       };
       expectation.addExpectationResult(pass, res);
      }

      function defaultNegativeCompare() {
        var result = matcher.compare.apply(null, args);
        if (webdriver.promise.isPromise(result.pass)) {
          result.pass = result.pass.then(function(pass) {
            return !pass;
          });
        } else {
          result.pass = !result.pass;
        }
        return result;
      }
    }