protractor icon indicating copy to clipboard operation
protractor copied to clipboard

"Error while waiting for Protractor to sync with the page" when navigating with window.location.href

Open sJhonny opened this issue 12 years ago • 10 comments

All my tests are working well on chrome, but on firefox I (sometimes) get the following error:

Error while waiting for Protractor to sync with the page: {"message":"angular.element(...).injector(...) is undefined","stackTrace":[{"fileName":"http://localhost/app/main#/home","lineNumber":72,"methodName":"anonymous/<"},{"fileName":"http://localhost/app/main#/home","lineNumber":77,"methodName":"anonymous"},{"fileName":"http://localhost/app/main#/home","lineNumber":68,"methodName":"handleEvaluateEvent"}]}

after which, every consequent test run fails with the same message; I have to re-start the webdriver-manager in order to get things to work again.

All my tests begin with a login action (fill in username and password, click 'login' and be redirected to the home page). That error occurs when redirecting to the homepage- after the login button was clicked, but before the home page has a chance to load.

after this error occurs I have to forcefully end all nodeJS processes to get things going again.

I'm running the latest protractor and webdriver-manager (0.20.1), latest firefox (27.0.1) on win8. This also happened with protractor 0.19.1 and firefox 26.

I'm not sure what's the source of the issue is, so I don't know what code I can post here.. Can anyone point at any possible cause for this?

EDIT: Forgot to mention I'm using angular 1.2.9

Also I've found that this error message repeats on every test run, except for the very first run. However, If I shutdown all NodeJS processes (shown in windows task manager as 'evented I/O for v8 javascript) EXCEPT for one (the main-loop thread of the webdriver-manager, I assume, since webdriver-manager stays alive) after every run, then this problem does not appear. This may suggest some issue with improper cleanup after tests have run...

I've also found that after getting this error with FF, the problem may appear with chrome on subsequent runs, unless I completely shut down the webdriver-manager. This also may indicate that something is lingering with the selenium server after the firefox tests finish. (of course- it may not; I've really no clue here :))

sJhonny avatar Mar 10 '14 13:03 sJhonny

Hm - does it work if you just shut down your localhost server and then restart? I wonder if your app is keeping state somehow, and that's messing it up.

juliemr avatar Mar 10 '14 17:03 juliemr

no, I don't keep any state. I just tested with resetting the application, and the problem still persisted. I played around with it some more, and I have some more observations (although I can't make much sense of them):

  1. My app is an SPA; the only complete page load is when transferring from the login page to the home page. And this is where the problem occurs; The navigation from the login page to the home page is done with
$http.post('/loginService, data)
            .success(function(response) {
                var newPath = decodeURIComponent(response['url']);
                window.location.href = newPath;
            });

Login page is also written with angular.

  1. I've noticed that I don't get this error if the FF developer tools are open during the test. (frankly that only served to confuse me further.. :))
  2. I've tried this with IE driver; again, I encountered problems with the navigation from the login page to the home page. error messages were a little different though- Error while waiting for Protractor to sync with the page: {"description":"'angular' is undefined","number":-2146823279,"stack":"ReferenceError: 'angular' is undefined\n at Anonymous function (Unknown script code:25:5)\n at Anonymous function (Unknown script code:21:14)\n at Anonymous function (Unknown script code:21:2)"} Error while waiting for Protractor to sync with the page: {"description":"Unable to get property 'get' of undefined or null reference","number":-2146823281,"stack":"TypeError: Unable to get property 'get' of undefined or null reference\n at Anonymous function (Unknown script code:25:5)\n at Anonymous function (Unknown script code:21:14)\n at Anonymous function (Unknown script code:21:2)"} UnknownError: Page reload detected during async script (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 1.31 seconds

sJhonny avatar Mar 11 '14 09:03 sJhonny

OK, did some more investigating, in 2 avenues:

  1. use vanilla webdriverJS with my original application
  2. change my application to redirect, instead of to the homepage, to a really simple Angular page.

Findings-

  1. pure webdriverJS works perfectly with both FF and IE (of course chrome also). my script for logging in and navigating inside the homepage is as follows:
var driver = new webdriver.Builder().
    withCapabilities(webdriver.Capabilities.firefox()).
    build();

driver.get('http://localhost/app/account#/login');

driver.findElement(webdriver.By.css('input[data-ng-model="username"]')).sendKeys('admin');
driver.findElement(webdriver.By.css('input[data-ng-model="password"]')).sendKeys('sisense');
driver.findElement(webdriver.By.css('button')).click();
driver.wait(function() {
    return driver.getTitle().then(function(title) {
        return title === 'homepage';
    });
}, 4000);

// on the homepage, navigate to a folder
driver.findElements(webdriver.By.css('.li-title.ng-binding'))
    .then(function(arr){
        arr[5].click();
    });

driver.wait(function() {
    return driver.getTitle().then(function(title) {
        return title !== 'homepage';
    });
}, 4000);

driver.quit();
  1. redirecting to a simpler homepage works ok in FF but still gives the same error as above in IE

(my protractor test is-

describe('login page', function() {

    it('should log in as admin', function(){
        // navigate to login page
        browser.get('account#/login');
        // type into inputs
        element(by.model('username')).sendKeys('admin');
        element(by.model('password')).sendKeys('kuku');
        // click the login button
        $('button').click();

        // assert that we're logged into the homepage
        expect(browser.getCurrentUrl()).toContain('main#/home');
    });

});

) the error message on IE is still- Error while waiting for Protractor to sync with the page: {"description":"Unable to get property 'get' of undefined or null reference","number":-2146823281,"stack":"TypeError: Unable to get property 'get' of undefined or null reference\n at Anonymous function (Unknown script code:25:5)\n at Anonymous function (Unknown script code:21:14)\n at Anonymous function (Unknown script code:21:2)"}

So I'm guessing the failure is somehow to do with the way protractor interacts with my application. But what should I look into when trying to troubleshoot this?

sJhonny avatar Mar 12 '14 09:03 sJhonny

(whoops accidentally closed the issue.. sorry)

sJhonny avatar Mar 12 '14 09:03 sJhonny

I'm guessing the window.location.href call in your login is what's messing Protractor up.

If you use Plain Old WebDriver for just the action after $('button').click(), does it work? E.g.

$('button').click();
browser.driver.wait(function() {
    return driver.getTitle().then(function(title) {
        return title === 'homepage';
    });
}, 4000);

// assert that we're logged into the homepage
expect(browser.getCurrentUrl()).toContain('main#/home');
// continue testing...

juliemr avatar Mar 12 '14 20:03 juliemr

yes; the code you provided here is almost exactly the same as the one I posted a couple of comments ago (under "pure webdriverJS works perfectly with both FF and IE ...") :)

So what would you suggest to use instead of window.location.href? using the $location service inside a http success gives the 'digest is already in progress' error; I saw that the window.location.href is the suggested solution (http://stackoverflow.com/a/14387747)

sJhonny avatar Mar 13 '14 08:03 sJhonny

For now, I'd suggest doing what I posted - using driver to deal with the part that uses window.location.href.

In the future, we should explore ways to make Protractor more graceful when page reloads occur. This may be challenging because WebDriver can't handle running scripts in the middle of a page reload.

juliemr avatar Mar 13 '14 23:03 juliemr

oh, i missed the browser.driver bit of your answer :P Yep, that worked well, thanks! I've changed the subject of this issue to match the actual problem and its symptom, in case anyone else searches for it; It may be a good idea to add this to the docs in some way, as a known issue. Cheers!

sJhonny avatar Mar 16 '14 07:03 sJhonny

I had the same issue when using the $location service with multiple instances of Firefox. The mentioned fix, of using webdriver, worked well.

warreng avatar Nov 24 '15 12:11 warreng

I am also getting the same error ERROR : Error while waiting for Protractor to sync with the page: "Unable to get property '$$testability' of undefined or null reference"

conf.js exports.config = { framework: 'jasmine2', seleniumAddress:'http://localhost:4444/wd/hub', capabilities: { 'browserName': 'internet explorer', 'ignoreProtectedModeSettings': true, 'count' : 3, },

specs: ['maintest.js'],
allScriptsTimeout: 100000,
getPageTimeout : 100000,

jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 1000000,
    isVerbose: true,
},

};

maintest.js:

describe('Atos Factory Maintenance web app', function() {

var homePage = require('C:/Users/A622864/WebstormProjects/sample/homePage.js'); var loginPage = require('C:/Users/A622864/WebstormProjects/sample/loginPage.js'); var assingJob = require('C:/Users/A622864/WebstormProjects/sample/assingJob.js'); var assignjobTask = require('C:/Users/A622864/WebstormProjects/sample/assignjobTask.js');

it('Verify the HomePage', function(){

 homePage.loadURL();
 expect(browser.getTitle()).toEqual('Factory Maintenance');
 console.log('HomePage test case is passed..!!');	

});

it('Verify the LoginPage',function(){

 loginPage.UserName();
 loginPage.Password();
 loginPage.clickLogin();
 console.log('Login is successful..!!');	 

});

it('Verify the title assign job task to technicain', function(){

assingJob.Clickassinjob();
console.log(' Assign job task link is worked successfully');

});

it('Verify the Job task', function(){

assignjobTask.SelectLoc();
assignjobTask.EntertaskDescription();
assignjobTask.SelectUserJob();
assignjobTask.ClickSubmit();
console.log('....');

});

});

image

makwanaparth94 avatar May 17 '17 06:05 makwanaparth94