title: Wait for page redirection in Protractor / Webdriver
body: <p>I have a test that clicks a button and redirects to a user dashboard. When this happens Webdriver returns:
  <code>javascript error: document unloaded while waiting for result.</code></p>
  
  <p>To fix this I insert <code>browser.sleep(2000)</code> at the point where redirection occurs and assuming my CPU usage is low, this solves the issue. However, 2000 ms is arbitrary and slow. Is there something like <code>browser.waitForAngular()</code> that will wait for the angular to load on the redirected page before the <code>expect(..)</code>?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>it('should create a new user', () =&gt; {
    $signUp.click();
    $email.sendKeys((new Date().getTime()) + '@.com');
    $password.sendKeys('12345');
    $submit.click();
  
    browser.sleep(2000); // Need alternative to sleep...
  
    // This doesn't do it...
    // browser.sleep(1);
    // browser.waitForAngular();
  
    $body.evaluate('user')
    .then((user) =&gt; {
      expect(user).toBe(true);
    });
  });</code></pre>
  </div>
  </div>
  </p>