angularjsoauthprotractorangularjs-e2e

e2e protractor test requiring oauth authentication


I've got an Angular app that requires authentication with Google, granting of some scopes, etc, and I'm trying to set up automatic e2e tests for it. I have protractor working well for me in general, but when we get to the google auth page, login, and get redirected, protractor fails the test because "document unloaded while waiting for result."

Is there a tool or technique I can use to authenticate to a development google account beforeEach test?

If I could just get the framework to hold on for a second while plain-old webdriver drives the login, and only really activate the angular stuff after I get to my target page, that would be perfect!


Solution

  • You should use waitForAngularEnabled to enable/disable waiting for Angular tasks with protractor. By default it will be enabled. You can use the following:

    // do things on your Angular application
    // go to external oauth page
    
    waitForAngularEnabled(false)
    
    // login on oauth page and redirect to your Angular application
    
    waitForAngularEnabled(true)
    browser.get('/home') // this is a page from your Angular application
    

    waitForAngularEnabled returns a promise. The browser.get function blocks until the Angular page is loaded.