javascriptangularjsprotractorangularjs-e2e

Protractor: Non angular login to angular site


Before I can reach the site to be tested I have to visit a login (non-angular) page first

var url = 'http://localhost:9999/login?usern=bar';
browser.driver.get(url);

Although that is a non-angular page, passing the ?usern=bar into the url the server gives an HTTP CODE of 302, and redirects to the page /new-user. Inside the new-user page I have to click a button before I can begin testing

But whatever I do I always get

Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.

There is something wrong in my flow, because I can see the new-user page, but the button is not clicked (and long after that the errors appear)

The spec file:

var Site = require('helper/site');

describe('Main', function {
    beforeAll(function () {
        return Site.login();
    });

    it('should show the main page', function () {
        epect(browser.getCurrentUrl()).toMatch(/\/main/);
    });
});

Site.js:

function login() {
    browser.driver.get('http://localhost:9999/login?usern=bar');

    browser.driver.wait(function () {
        return browser.driver.getCurrentUrl().then(function (url) {
            return /\/new-user/.test(url);
        });
    });

    element(by.css('.save')).click();
}

module.exports = {
    login: login
};

Any help would be appreciated


Solution

  • You have to turn the sync off:

    describe('Main', function {
        beforeAll(function () {
            browser.ignoreSynchronization = true;
            return Site.login();
        });
    
        it('should show the main page', function () {
            browser.ignoreSynchronization = false;
    
            expect(browser.getCurrentUrl()).toMatch(/\/main/);
        });
    });
    

    Though, think of better places to turn it off and then on again once you are on the main page.