Protractor: Error while waiting for Protractor to sync with the page: "both angularJS testability and angular testability are undefined

拈花ヽ惹草 提交于 2020-05-14 18:42:05

问题


I am trying to write some end to end tests and waned to use async and await.

configuration file

exports.config = {
    framework: 'jasmine',
    seleniumAddress: 'http://localhost:4444/wd/hub',
    specs: ['spec.js'],
    SELENIUM_PROMISE_MANAGER: false,
    getPageTimeout: 10000,
    multiCapabilities: [
        {
            browserName: 'firefox'
        }, {
            browserName: 'chrome'
        }
    ]
}

spec file

    describe('home-view', function(){

    beforeEach(async function(){

        await browser.get('http://localhost:49335/index.html#!/home');

    });

    it('sorted by firstname', async function(){

        await element(by.css("[ng-click=\"sortData('firstname')\"]")).click();
        var firstname = element.all(by.repeater('a in emps')).all(by.css('td'));     
        expect(await firstname.get(0).getText()).toEqual('abraham');

    });

})

Error Error while waiting for Protractor to sync with the page: "both angularJS testability and angular testability are undefined. This could be either because this is a non-angular page or because your test involves client-side navigation, which can interfere with Protractor's bootstrapping."

Why do I get this error? Thanks


回答1:


You got this error because Protractor by default wait angular page is loaded. If you work with non angular you should add await browser.waitForAngularEnabled(false); to onPrepare block:

 onPrepare: async () => {
 ...
 await browser.waitForAngularEnabled(false);
 ...  

How does this "waiting" mechanism works? I will copy description from code:

     * If set to false, Protractor will not wait for Angular $http and $timeout
     * tasks to complete before interacting with the browser. This can cause
     * flaky tests, but should be used if, for instance, your app continuously
     * polls an API with $timeout.

So, as you can see it is all about $http and $timeout tasks. A bit often developers use it in a not proper way.

In conclusion, if you see such error:

both angularJS testability and angular testability are undefined

you have to add await browser.waitForAngularEnabled(false);.




回答2:


Give the getPageTimeOut more than 20 sec. Use explicit wait like browser.sleep(2000) after browser.get method. The error occured may be because of slow response from webpage and also use dirctConnect instead of seleniumAddress.




回答3:


Earlier All I needed to add this in my script.js browser.driver.ignoreSynchronization = true;

However adding this solved my problem. browser.waitForAngularEnabled(false);

So altogether final script.js is

describe('My first non angular class', function() {
    it('My function', function() {
        browser.driver.ignoreSynchronization = true;
        browser.waitForAngularEnabled(false);
        browser.driver.manage().window().maximize();
        //browser.get('http://juliemr.github.io/protractor-demo/');
        browser.driver.get('https://stackoverflow.com/users/login');
        element(by.id('email')).sendKeys('6');

    })

}) 


来源:https://stackoverflow.com/questions/54977422/protractor-error-while-waiting-for-protractor-to-sync-with-the-page-both-angu

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