I have a Google Auth page object (below) that does the whole job for me.
The key here is "isAngularSite(false);" function witch instructs webdriver if we are entering 'angular' or 'non angular' website.
(implementation below).
/* global element, browser, by */
'use strict';
var GOOGLE_USERNAME = '[email protected]';
var GOOGLE_PASSWORD = 'password';
var ec = protractor.ExpectedConditions;
var Google = function () {
this.emailInput = element(by.id('Email'));
this.passwordInput = element(by.id('Passwd'));
this.nextButton = element(by.id('next'));
this.signInButton = element(by.id('signIn'));
this.approveAccess = element(by.id('submit_approve_access'));
this.loginToGoogle = function () {
var self = this;
/* Entering non angular site, it instructs webdriver to switch
to synchronous mode. At this point I assume we are on google
login page */
isAngularSite(false);
this.emailInput.sendKeys(GOOGLE_USERNAME);
this.nextButton.click();
this.passwordInput.isPresent().then(function () {
browser.wait(ec.visibilityOf(self.passwordInput), BROWSER_WAIT).then(function () {
self.passwordInput.sendKeys(GOOGLE_PASSWORD);
self.signInButton.click();
browser.wait(ec.elementToBeClickable(self.approveAccess), BROWSER_WAIT).then(function () {
self.approveAccess.click();
/* Now we are being redirected to our app, switch back to
async mode (page with angular) */
isAngularSite(true);
});
});
});
}
}
module.exports = new Google();
--- throw this into protractor.conf.js
onPrepare: function () {
global.isAngularSite = function (flag) {
console.log('Switching to ' + (flag ? 'Asynchronous' : 'Synchronous') + ' mode.')
browser.ignoreSynchronization = !flag;
},
global.BROWSER_WAIT = 5000;
}
--- that's how you would use it:
it('should login though google', function(done) {
mainPage.loginBtn.click().
then(function () {
loginPage.connectWithGoogleBtn.click();
googlePage.loginToGoogle();
browser.wait(mainPage.userName.isPresent()).
then(function () {
expect(mainPage.userName.getText()).
toEqual('[email protected]');
done();
});
});
});
waitForAngularEnabled
is available we should use that instead of sleep timers. Set the timer too high and your tests will take long, set them too low and your tests may fail. This answer will immediately continue with testing your Angular application the moment we switch back from the oauth page. – Dogeared