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

后端 未结 3 1510
温柔的废话
温柔的废话 2021-01-17 14:02

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

configuration file

exports.config = {
    framework: \'jasmine\',
             


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-17 14:09

    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);.

提交回复
热议问题