title: How do I correctly inject a login service in a beforeEach for protractor e2e tests using chromedriver?
body: <p>The test currently looks like</p>
  
  <blockquote>
  <pre><code>describe('if authenticated', function() {
    beforeEach(function() {
      var ptor = protractor.getInstance();
      ptor.waitForAngular();
      browser.executeAsyncScript(function() {
        var callback = arguments[arguments.length - 1];
        var loginService = angular.injector(['ng', 'firebase', 'myApp.config', 'myApp.service.firebase', 'myApp.service.login']).get('loginService');
        loginService.init();
        loginService.login(browser.params.login.user, browser.params.login.password, callback);
        callback(null, true);
      });
    });
  
    it('should stay on account screen if authenticated', function() {
      browser.get('/app/index.html#/account');
  
      // expect(browser.window().hash()).toBe('/account');
      expect(browser.getCurrentUrl()).toMatch(/\/account/);
    });
  });
  </code></pre>
  </blockquote>
  
  <p>There are two errors that I can't get around, either 'Error while waiting for Protractor to sync with the page: {}' or 'unknown error: angular is not defined', depending on the waitForAngular call.</p>
  
  <p>How can I accomplish this so that the test passes?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I also see 'UnknownError: javascript error: browser is not defined', if I run that test as part of the test suite (all other tests pass).</p>
  
  <p>This is the only test that tries to inject the loginService in the beforeEach for an authenticated page.  Getting access to angular in the afterEach seems to work as expected.</p>
  
  <p><strong>File</strong> config/protractor.conf.js</p>
  
  <pre><code>exports.config = {
    // The address of a running selenium server.
    seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
    baseUrl: 'http://localhost:' + (process.env.HTTP_PORT || '8000'),
  
    // Capabilities to be passed to the webdriver instance.
    capabilities: {
      'browserName': 'chrome'
    },
  ...
  </code></pre>