代码之家  ›  专栏  ›  技术社区  ›  Thunfische

量角器:等待量角器与页面同步时出错:“angularJS可测试性和angular可测试性都未定义

  •  0
  • Thunfische  · 技术社区  · 7 年前

    配置文件

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

        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');
    
        });
    
    })
    

    错误 等待量角器与页面同步时出错:“angularJS可测试性和angular可测试性都未定义。这可能是因为这是一个非角度页面,也可能是因为您的测试涉及客户端导航,这可能会干扰量角器的引导。”

    0 回复  |  直到 7 年前
        1
  •  13
  •   Gerhard    6 年前

    出现此错误是因为默认情况下加载了量角器等待角度页。如果你用非角度的,你应该加上 await browser.waitForAngularEnabled(false); onPrepare 块:

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

    这种“等待”机制是如何工作的?我将从代码中复制描述:

         * 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.
    

    $http $timeout 任务。开发人员经常以不恰当的方式使用它。

    总之,如果您看到这样的错误:

    both angularJS testability and angular testability are undefined
    

    wait browser.waitForAngularEnabled(false); .

        2
  •  0
  •   Dixit_Autobot    7 年前

    让getPageTimeOut超过20秒。在browser.get方法之后使用显式的wait-like browser.sleep(2000)。发生错误的原因可能是网页响应慢,并且使用dirctConnect代替seleniumAddress。

        3
  •  0
  •   Sameera De Silva    6 年前

    之前我只需要在script.js中添加这个

    但是添加这个解决了我的问题。 browser.waitForAngularEnabled(false);

    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');
    
        })
    
    })