1

I am trying to test a basic login/logout from my site. the entry point to my angular app is from a non-angular login page (oauth), which then serves the app after credentials have been validated. My test will run locally but not on Circle Ci; my error is this;

Message:
    Failed: Error while waiting for Protractor to sync with the page: "angular could not be found on the window"
  Stack:
Error: Failed: Error while waiting for Protractor to sync with the page: "angular could not be found on the window"

here is my test function:

    it('Log into Webapp', function() {
     browser.ignoreSynchronization = true;
        browser.manage().timeouts().pageLoadTimeout(40000);
        browser.manage().timeouts().implicitlyWait(25000);

        browser.get('http://localhost:8000/login');

        element(by.id('username')).sendKeys('x..');
        element(by.id('password')).sendKeys('...');
        element(by.name('Login')).click();

        setTimeout(function(){}, 15000);
        element(by.name('save')).click();

        setTimeout(function(){}, 10000);
        //browser.waitForAngular();
        //browser.ignoreSynchronization = false;
        //browser.ignoreSynchronization = false;
        // Angular app should be served, Logout is on this
        browser.ignoreSynchronization = false;

        element(by.name('logoutBtn')).click();

});
tauren.kristich
  • 449
  • 1
  • 6
  • 22

2 Answers2

4

Try moving ignoreSynchronization to beforeEach and afterEach:

beforeEach(function () {
    browser.ignoreSynchronization = true;
});

afterEach(function () {
    browser.ignoreSynchronization = false;
});

Helped me to solve: Non-angular page opened after a click.

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • 1
    A truly non-Angular website could probably have browser.ignoreSynchronization moved to beforeAll and be fine, but this is a very good starting point. – MBielski Oct 05 '15 at 14:50
  • @alecxe but beforeEach will affect the angular specs (`it`) too, right? If at all there are any of them in the test suite (`describe`). – giri-sh Oct 05 '15 at 14:55
  • @GirishSortur yeah, that could become a problem, let's see what the OP would say, thanks! – alecxe Oct 05 '15 at 14:56
1

Replace setTimeout calls with browser.sleep(10000);

setTimeout executes a callback function after the timeout, but the main "thread" continues its execution flow. So you are not really waiting.

Also, you could use browser.waitForAngular() before the last logoutBtn click.

Something like this:

it('Log into Webapp', function() {
    browser.ignoreSynchronization = true;
    browser.manage().timeouts().pageLoadTimeout(40000);
    browser.manage().timeouts().implicitlyWait(25000);

    browser.get('http://localhost:8000/login');

    element(by.id('username')).sendKeys('x..');
    element(by.id('password')).sendKeys('...');
    element(by.name('Login')).click();

    browser.sleep(15000);
    element(by.name('save')).click();

    browser.sleep(10000);
    browser.waitForAngular();        

    element(by.name('logoutBtn')).click();

    // Angular app should be served, Logout is on this
    browser.ignoreSynchronization = false;

});

hhaamm
  • 398
  • 1
  • 2
  • 13
  • isn't it bad practice to introduce sleep commands in testing code ? when you compound these explicit sleeps over the test cycle you end up with wasted time, or, on occasion, not enough wait time because you must wait , even if what you're looking for on the page is already there, or the sleep was not long enough and this broke your test – Dror Apr 10 '16 at 06:56
  • Yeah I totally agree but if this guy is using sleep calls, he should use `browser.sleep()`, not `setTimeout`. – hhaamm Apr 10 '16 at 14:15