text: /**
   *
   * Wait for an element (selected by css selector) for the provided amount of
   * milliseconds to have text/content. If multiple elements get queryied by given
   * selector, it returns true (or false if reverse flag is set) if at least one
   * element has text/content.
   *
   * <example>
      :index.html
      <div id="elem"></div>
      <script type="text/javascript">
          setTimeout(function () {
              document.getElementById('elem').innerHTML = 'some text';
          }, 2000);
      </script>
  
      :waitForTextExample.js
      it('should detect when element has text', function () {
          elem = browser.element('#elem');
          elem.waitForText(3000)
      });
   * </example>
   *
   * @param {String}   selector element to wait for
   * @param {Number=}  ms       time in ms (default: 500)
   * @param {Boolean=} reverse  if true it waits for the opposite (default: false)
   *
   * @uses util/waitUntil, property/getText
   * @type utility
   *
   */
  
  'use strict';
  
  var _getIterator = require('babel-runtime/core-js/get-iterator')['default'];
  
  Object.defineProperty(exports, '__esModule', {
      value: true
  });
  
  var _utilsErrorHandler = require('../utils/ErrorHandler');
  
  var waitForText = function waitForText(selector, ms, reverse) {
      var _this = this;
  
      /**
       * we can't use default values for function parameter here because this would
       * break the ability to chain the command with an element if reverse is used, like
       *
       * ```js
       * var elem = browser.element('#elem');
       * elem.waitForXXX(10000, true);
       * ```
       */
      reverse = typeof reverse === 'boolean' ? reverse : false;
  
      /*!
       * ensure that ms is set properly
       */
      if (typeof ms !== 'number') {
          ms = this.options.waitforTimeout;
      }
  
      return this.waitUntil(function () {
          return _this.getText(selector).then(function (text) {
              if (!Array.isArray(text)) {
                  return text !== '' !== reverse;
              }
  
              var result = reverse;
              var _iteratorNormalCompletion = true;
              var _didIteratorError = false;
              var _iteratorError = undefined;
  
              try {
                  for (var _iterator = _getIterator(text), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
                      var val = _step.value;
  
                      if (!reverse) {
                          result = result || val !== '';
                      } else {
                          result = result && val === '';
                      }
                  }
              } catch (err) {
                  _didIteratorError = true;
                  _iteratorError = err;
              } finally {
                  try {
                      if (!_iteratorNormalCompletion && _iterator['return']) {
                          _iterator['return']();
                      }
                  } finally {
                      if (_didIteratorError) {
                          throw _iteratorError;
                      }
                  }
              }
  
              return result !== reverse;
          });
      }, ms)['catch'](function (e) {
          if ((0, _utilsErrorHandler.isTimeoutError)(e)) {
              var isReversed = reverse ? 'with' : 'without';
              throw new _utilsErrorHandler.WaitUntilTimeoutError('element (' + selector + ') still ' + isReversed + ' text after ' + ms + 'ms');
          }
          throw e;
      });
  };
  
  exports['default'] = waitForText;
  module.exports = exports['default'];
  