title: Protractor wait for rest call finish
body: <p>I have simple scenario that I want to test if I am able to delete some object. So scenario looks like:</p>
  
  <p>1 Add by rest call some unique object(without using browser, and I dont want to use before each/all because it is specific only for this test)</p>
  
  <p>2 Delete above object in web application</p>
  
  <p>So I wrote simulation of my code:</p>
  
  <pre><code>it('test promise', function(done) {
      console.log('start');
      d = protractor.promise.defer();
      setTimeout(function() {
          console.log("rest call");
          d.fulfill('ok');
          done();
      }, 3000);
      console.log('before expect');
      expect(d).toBe('ok'); //code should be stoped here till rest above finish
      console.log('after expect');
      console.log('rest test based on deffer result');
      console.log('change tab... find elements... click to delete...');
  });
  </code></pre>
  
  <p>ouput of this code is:</p>
  
  <pre><code>start
  before expect
  after expect
  change tab... find elements... click to delete...
  rest call
  </code></pre>
  
  <p>So as you can see rest call is run after I will make all webdriver actions...
  Some ideas?</p>
  
  <p>Edit:</p>
  
  <p>I've added control flow but it still not works. For code:</p>
  
  <pre><code>it('test promise', function(done) {
      console.log('start');
      flow = protractor.promise.controlFlow();
      var d = protractor.promise.defer();
      var restCall = function _makeRestCall() {
          setTimeout(function () {
              console.log("rest call");
              d.fulfill('ok');
          }, 3000);
          return d.promise
      };
      console.log('before expect');
      flow.execute(restCall);
      // expect(d).toBe('ok'); //version 1 not work
      expect(restCall).toBe('ok'); //version 2 not work
      console.log('after expect');
      console.log('rest test based on deffer result');
  });
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>start
  before expect
  after expect
  rest test based on deffer result
  rest call
  </code></pre>