title: Protractor tests inconsistently passing / failing for AngularJS app
body: <p>My Protractor e2e tests are inconsistently passing and failing.</p>
  
  <p>It seems this could be due to asynchronous javascript, as discussed here:
  <b><a href="https://stackoverflow.com/questions/21748442/protractor-how-to-wait-for-page-complete-after-click-a-button">Protractor : How to wait for page complete after click a button?</a></b>. </p>
  
  <p>However, here it's mentioned that Protractor tests automatically execute sequentially / synchronously:
  <b><a href="https://github.com/angular/protractor/issues/909" rel="noreferrer">https://github.com/angular/protractor/issues/909</a></b> </p>
  
  <p>My test script:</p>
  
  <pre><code>describe('Login', function() {
  
    var ptor;
  
    beforeEach(function() {
      browser.get('https://127.0.0.1:8443');
      ptor = protractor.getInstance();
      element(by.id('splash')).click();
      browser.ignoreSynchronization = true;  // &lt;-- to proceed beyond splash screen
    });
  
    describe('with correct email and password', function() {
  
      beforeEach(function() {
          element(by.id('email')).sendKeys('admin@email.com');
          element(by.id('password')).sendKeys('adminpassword');
          element(by.id('loginButton')).click();
      });
  
      afterEach(function() {
          ptor.findElement(by.id('logout')).then(function(elem) {
              elem.click();
          });
      });
  
      it('does not show alert', function() {  // &lt;-- sometimes passes, sometimes fails
          expect(browser.isElementPresent(by.css('.alert-danger'))).toBe(false);
      });
  
      it('changes route to /admin', function() {  // &lt;-- sometimes passes, sometimes fails
          expect(browser.getCurrentUrl()).toMatch(/\/admin/);
      });
    });
  });
  </code></pre>
  
  <p>In the two tests above, either <b>both tests will pass</b>, or <b>one/both of the tests will fail</b> with these messages:</p>
  
  <pre><code>Failures:
  
  1) Login with correct email and password does not show alert
  Message:
    NoSuchElementError: no such element
  ...
  ==== async task ====
  WebDriver.findElement(By.id("logout"))
  ...
  </code></pre>
  
  <p>or</p>
  
  <pre><code>Failures:
  
  1) Login with correct email and password changes route to /admin
  Message:
    NoSuchElementError: no such element
  ...
  ==== async task ====
  WebDriver.findElement(By.id("logout"))
  ...
  </code></pre>
  
  <p>Thoughts / help much appreciated.</p>