Javascript 量角器:如何等待引导的AngularJS满负荷

Javascript 量角器:如何等待引导的AngularJS满负荷,javascript,angularjs,protractor,Javascript,Angularjs,Protractor,我有一个自举的Angular(1.2.6)应用程序。这意味着它没有显式的ng应用程序。因此,我在让量角器框架的测试工作时遇到了各种各样的问题(使用SauceLabs和grunt量角器runner) 错误根据我的尝试而有所不同,但通常: Error: Angular could not be found on the page http://xxx:9000/ : angular never provided resumeBootstrap 或者 我已经找到了一些我尝试过的解决方案。包括在中

我有一个自举的Angular(1.2.6)应用程序。这意味着它没有显式的
ng应用程序
。因此,我在让量角器框架的测试工作时遇到了各种各样的问题(使用SauceLabs和grunt量角器runner)

错误根据我的尝试而有所不同,但通常:

 Error: Angular could not be found on the page http://xxx:9000/ :
 angular never provided resumeBootstrap
或者

我已经找到了一些我尝试过的解决方案。包括在中发现的,以及。不过,我所做的一切都不能让事情顺利进行

我曾尝试在引导过程中使用
angular.resumeBootstrap
(注意,我尝试了多种不同的方法,但均无效,包括尝试在文档正文上以编程方式设置ng应用程序):

正如其他人所发现的那样,这个错误很奇怪:

UnknownError: unknown error: [ng:btstrpd] App Already Bootstrapped with this Element
'<body ng-app="" ng-controller="ApplicationController" class=" ng-scope pace-done">'
这会导致如下错误:

1) e2e: home should load the home page
  Message: timeout: timed out after 20000 msec waiting for spec to complete
  Stacktrace: undefined
我还尝试在配置文件中增加各种超时,但都没有效果


任何帮助都将不胜感激

您应该将测试分为两个“it”步骤。像这样:

it( 'should load angular', function() {
  ptor = protractor.getInstance();
  ptor.waitForAngular();
})

it( 'should load the home page', function() {
  ptor.driver.get( 'http://xxx:9000/' );
  ptor.driver.wait( function() {
    return ptor.getCurrentUrl().then( function() {
      return ptor.isElementPresent( by.id( 'signIn' ) ).then( function()     {
        console.log('we are here!');
        return true;
      });
    });
  })
  .then( function() {
    expect( ptor.isElementPresent( by.id( 'signIn' ) ) ).toBe( true );
  });
});

量角器的问题是,每个命令都会在不等待前一步完成的情况下运行。所以,
ptor.waitForAngular()和
ptor.driver.get('http://xxx:9000/)
几乎同时运行。如果将它们分为两个步骤,量角器将在第一个“it”步骤完成后继续移动。

@alecxe
grunt量角器-runner@1.1.4
protractor@1.4.0
。我正在运行这两个版本的早期版本,升级(认为这会有所帮助)。。。错误方面没有(明显的)差异。我不确定这是否有帮助,但请尝试将量角器降级到早期版本。@alecxe是的,以前尝试过
protractor@0.24.2
(!)和相同的结果。我忘了提到protor.getInstance()已被弃用。改为使用浏览器这对我使用require.js手动引导的应用程序很有效。我只使用browser.waitForAngular()放置了一个前置“it”块,并在量角器配置文件中设置browser.ignoreSynchronization=true。它看起来很粗糙,但它起作用了。唷。更正,这只在某些时候对我有效。非常令人沮丧的是,我仍然会在完全相同的测试中遇到间歇性错误。这是因为“browser.ignoreSynchronization=true”将导致量角器忽略Angular的$timeout和$http调用,这将导致不稳定的测试结果。小心使用“ignoreSynchronization”。
it
测试中的块应相互独立,因为它们的运行顺序不受保证。因此,这种方法有时有效,有时无效。
it( 'should load the home page', function() {
  ptor = protractor.getInstance();
  ptor.waitForAngular();
  ptor.driver.get( 'http://xxx:9000/' );
  ptor.driver.wait( function() {
    return ptor.getCurrentUrl().then( function() {
      return ptor.isElementPresent( by.id( 'signIn' ) ).then( function() {
        console.log('we are here!');
        return true;
      });
    });
  })
  .then( function() {
    expect( ptor.isElementPresent( by.id( 'signIn' ) ) ).toBe( true );
  });
});
1) e2e: home should load the home page
  Message: timeout: timed out after 20000 msec waiting for spec to complete
  Stacktrace: undefined
it( 'should load angular', function() {
  ptor = protractor.getInstance();
  ptor.waitForAngular();
})

it( 'should load the home page', function() {
  ptor.driver.get( 'http://xxx:9000/' );
  ptor.driver.wait( function() {
    return ptor.getCurrentUrl().then( function() {
      return ptor.isElementPresent( by.id( 'signIn' ) ).then( function()     {
        console.log('we are here!');
        return true;
      });
    });
  })
  .then( function() {
    expect( ptor.isElementPresent( by.id( 'signIn' ) ) ).toBe( true );
  });
});