title: Using async and await in selenium protractor tests
body: <p>How do I use async and await in protractor tests?</p>
  
  <pre><code>it('test async', function(){
      var value = 0;
      function asyncAction() {
          return browser.driver.wait(()=&gt;true)
              .then(function () {
                  console.log('a');
                  return value++;
              });
      }
      //-Problem Area-
      async function doAwait(){
          await asyncAction();
          return asyncAction();
      }
  
      doAwait();
  
      protractor.promise.controlFlow().execute( () =&gt; {
          console.log('b');
          expect(value).toBe(2);
      });
  });
  </code></pre>
  
  <p>output here is </p>
  
  <ul>
  <li>a</li>
  <li>b</li>
  <li>a</li>
  </ul>
  
  <p>and value is 1 at time of expect
  function doAwait(){
          await asyncAction();
          return asyncAction();
      }</p>
  
  <p>I like to think of this as similar to</p>
  
  <pre><code>function doAwait(){
    asyncAction().then(()=&gt;asyncAction());
  }
  </code></pre>
  
  <p>Which works but the above async doAwait does not.  I believe this is because the generator breaks the ControlFlow of selenium.</p>