Error while waiting for Protractor to sync with the page: "window.angular is undefined

半城伤御伤魂 提交于 2019-12-22 10:27:21

问题


I've just started to use Protractor. I created several page objects and everything is working fine till now. I log in to a page and I'm being redirected to the myaccount page.

On that page, I got the following error: Error while waiting for Protractor to sync with the page: "window.angular is undefined.

My code is here:

var myaccount = function(){

//some function but everything is commented out
};
module.exports = new myaccount();

Here is my login test as well:

    this.loginSuccess = function(){
    userName.sendKeys(params.registration.email);
    password.sendKeys(params.registration.password);
    submitButton.click();
};

After the click, myaccount page appears but the protractor throws the mentioned error.

Could somebody help me with this?


回答1:


See the answer from mcalthrop here: https://github.com/angular/protractor/issues/610

Can use like

var newpage = new RegExp('welcome', 'i');
submitButton.click();
waitForUrlToChangeTo(newpage).then(function () {
        expect(browser.getTitle()).toEqual('Welcome!');
});
/**
 * @name waitForUrlToChangeTo
 * @description Wait until the URL changes to match a provided regex
 * @param {RegExp} urlRegex wait until the URL changes to match this regex
 * @returns {!webdriver.promise.Promise} Promise
 */
function waitForUrlToChangeTo(urlRegex) {
    var currentUrl;

    return browser.getCurrentUrl().then(function storeCurrentUrl(url) {
            currentUrl = url;
        }
    ).then(function waitForUrlToChangeTo() {
            return browser.wait(function waitForUrlToChangeTo() {
                return browser.getCurrentUrl().then(function compareCurrentUrl(url) {
                    return urlRegex.test(url);
                });
            });
        }
    );
}



回答2:


window.angular is undefined means you are trying to make protractor go to a page that is not angular



来源:https://stackoverflow.com/questions/34900470/error-while-waiting-for-protractor-to-sync-with-the-page-window-angular-is-und

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!