title: Resolve promise conditionally
body: <p>I'm using the automated testing framework, Protractor. </p>
  
  <p>I've come to find that Protractor frequently makes use of <code>promises</code> to asynchronously resolve code evaluation.</p>
  
  <p>Question: How can I manually resolve a promise to a specific value, once a condition is met? </p>
  
  <hr>
  
  <p>Update: 09/08/2017</p>
  
  <p>Sorry, I was just a bit unclear on <code>promises</code>. I was able to get this working correctly now with:</p>
  
  <pre><code>// match variable
  var match = false;
  
  // get all elements with `div` tag
  var scanElements = element.all(by.css('div')).each(function(el) {
      // get text content of element
      el.getText().then(function(text) {
          // split words into array based on (space) delimeter
          var sp = text.split(' ');
          for (var i = 0; i &lt; sp.length; i++) {
              if (sp[i] == 'Stack Overflow') {
                  match = true;
              }
          }
      });
  });
  
  // on complete
  scanElements.then(function() {
      if (match) {
          console.log('Status: Found match!');
      }
      else {
          console.log('Status: No match');
      }
  });
  </code></pre>