title: Protractor moves on to next test without waiting
body: <p>I'm using protractor and when I run my tests on <a href="http://www.browserstack.com" rel="nofollow noreferrer">browserstack</a> I receive the following error</p>
  
  <pre><code>StaleElementReferenceError: stale element reference: element is not attached to the page document
  </code></pre>
  
  <p>or depending on what I do in the  <code>beforeAll</code></p>
  
  <pre><code>Error: Index out of bound. Trying to access element at index: 0, but there are only 0 elements that match locator By.cssSelector ...
  </code></pre>
  
  <p>Here is the code snippet causing the error:</p>
  
  <pre><code>describe('...', () =&gt; {
     it('...', () =&gt; {
         expect(element.all(by.css(...)).count()).toBe(9);
         expect(element.all(by.css('.items').get(0).isDisplayed()).toBeTruthy();
     });
  }
  
  describe('', () =&gt; {
      beforeAll((/* done */) =&gt; {
           element(by.css('.go-home').click(); // .then(done); 
           //browser.driver.get('/');//.then(done);
      });
      ...
  });
  </code></pre>
  
  <p>For some reason the <code>beforeAll</code> continues and changes the url, while the previous <code>it</code> is still running (I guess based on the error). </p>
  
  <p>Now, I managed to hack this such that is works. I've added the <code>done</code> to the <code>it</code> as follows</p>
  
  <pre><code>describe('...', () =&gt; {
     it('...', (done) =&gt; {
         expect(element.all(by.css(...).count()).toBe(9);
  
         element.all(by.css(...)).get(0).isDisplayed().then((state) =&gt; {
            expect(state).toBeTruthy();
            done();
      });
     });
  }
  
  describe('', () =&gt; {
      beforeAll(() =&gt; {
           element(by.css('.go-home').click(); // works 
           //browser.driver.get('/');          // still fails
      });
      ...
  });
  </code></pre>
  
  <p>Now it works. However if I use <code>browser.driver.get('/')</code> it fails again.</p>
  
  <p>Normally I don't have to add <code>done</code> to my <code>it</code>s so my question is: What is going wrong here ? Any help would be appreciated</p>
  
  <p>UPDATE: protractor.config.js:</p>
  
  <pre><code>exports.config = {
      chromeDriver: '../node_modules/protra...medriver_2.25',
      seleniumServerJar: '../node_...-server-standalone-2.53.1.jar',
      exclude: [],
  
      specs: [
          '../test/e2e/**/*.js'
      ],
  
      multiCapabilities: [
          {
              build: 'test',
              project: 'ABC',
              browserName: 'firefox',
              //browserName: 'chrome',
              os: 'Windows',
              os_version: '10',
              directConnect: true
          }],
      debug: true,
      maxSessions: 1,
      framework: 'jasmine2',
  
      onPrepare: function () {
          browser.driver.manage().window().setSize(1024, 768);
  
          // Register helpers
          require('../test/framework/jasmine2');
  
          var disableNgAnimate = function () {
              angular
                  .module('disableNgAnimate', [])
                  .run(['$animate', function ($animate) {
                      $animate.enabled(false);
                  }]);
              };
  
          var disableCssAnimate = function () {
              angular
                  .module('disableCssAnimate', [])
                  .run(function () {
                      var style = document.createElement('style');
                      style.type = 'text/css';
                      style.innerHTML = '* {' +
                          '-webkit-transition: none !important;' +
                          '-moz-transition: none !important' +
                          '-o-transition: none !important' +
                          '-ms-transition: none !important' +
                          'transition: none !important' +
                          '}';
                      document.getElementsByTagName('head')[0].appendChild(style);
              });
          };
  
          browser.addMockModule('disableNgAnimate', disableNgAnimate);
          browser.addMockModule('disableCssAnimate', disableCssAnimate);
      }
  };
  </code></pre>