我偶尔会看到这个错误,仅在Jenkins上,但至少一次测试运行。如果我很幸运,它不会发生在每5或6个版本中:
Error: Error while waiting for Protractor to sync with the page: "root element ([ng-app]) has no injector. this may mean it is not inside ng-app."
at Error (<anonymous>)
at /home/tester/workspace/EncoreUI_Template_PR_Builder/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1526:15
at newFrame.onAbort (/home/tester/workspace/EncoreUI_Template_PR_Builder/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1679:7)
at [object Object].webdriver.promise.Frame_.notify_ (/home/tester/workspace/EncoreUI_Template_PR_Builder/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1914:5)
at [object Object]._onTimeout (/home/tester/workspace/EncoreUI_Template_PR_Builder/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1887:13)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
==== async task ====
Protractor.waitForAngular()
at [object Object].webdriver.WebDriver.schedule (/home/tester/workspace/EncoreUI_Template_PR_Builder/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:345:15)
at [object Object].Protractor.executeAsyncScript_ (/home/tester/workspace/EncoreUI_Template_PR_Builder/node_modules/protractor/lib/protractor.js:251:26)
at [object Object].Protractor.waitForAngular (/home/tester/workspace/EncoreUI_Template_PR_Builder/node_modules/protractor/lib/protractor.js:274:15)
at [object Object].to.(anonymous function) [as getCurrentUrl] (/home/tester/workspace/EncoreUI_Template_PR_Builder/node_modules/protractor/lib/protractor.js:60:7)
at Context.<anonymous> (/home/tester/workspace/EncoreUI_Template_PR_Builder/test/stories/loggingIn.js:37:32)
at /home/tester/workspace/EncoreUI_Template_PR_Builder/node_modules/protractor/node_modules/selenium-webdriver/testing/index.js:121:22
at [object Object].webdriver.promise.ControlFlow.runInNewFrame_ (/home/tester/workspace/EncoreUI_Template_PR_Builder/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1654:20)
at [object Object].webdriver.promise.ControlFlow.runEventLoop_ (/home/tester/workspace/EncoreUI_Template_PR_Builder/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1518:8)
at [object Object].wrapper [as _onTimeout] (timers.js:258:14)
==== async task ====
at Context.ret (/home/tester/workspace/EncoreUI_Template_PR_Builder/node_modules/protractor/node_modules/selenium-webdriver/testing/index.js:119:12)
at Test.Runnable.run (/home/tester/workspace/EncoreUI_Template_PR_Builder/node_modules/mocha/lib/runnable.js:218:15)
at Runner.runTest (/home/tester/workspace/EncoreUI_Template_PR_Builder/node_modules/mocha/lib/runner.js:374:10)
at /home/tester/workspace/EncoreUI_Template_PR_Builder/node_modules/mocha/lib/runner.js:452:12
at next (/home/tester/workspace/EncoreUI_Template_PR_Builder/node_modules/mocha/lib/runner.js:299:14)
at /home/tester/workspace/EncoreUI_Template_PR_Builder/node_modules/mocha/lib/runner.js:309:7
at next (/home/tester/workspace/EncoreUI_Template_PR_Builder/node_modules/mocha/lib/runner.js:248:23)
at Object._onImmediate (/home/tester/workspace/EncoreUI_Template_PR_Builder/node_modules/mocha/lib/runner.js:276:5)
at processImmediate [as _immediateCallback] (timers.js:336:15)
我发现在我的测试的本地运行或Travis上似乎不会发生错误。但是,在运行firefox,xvfb和Protractor 1.7.0的Jenkins奴隶上,我经常遇到这个错误。至少一次测试。
我已将我的配置文件更新为指向&#39; [ng-app]&#39;作为我的rootElement。
我在the angular getTestability
docs中看到它被抛出&#34;通常因为根元素在ng-app&#34;之外,但在这种情况下选择器返回OK,所以我&#39;我想知道为什么根元素不会有注射器的其他原因。
答案 0 :(得分:4)
问题分为两部分。其一,Jenkins在VM上运行,并且CPU功率和网络连接速度比本地机器少,这解释了为什么它从未出现在本地。第二部分与被测应用程序的体系结构有关。通常,Angular应用程序被设计为单页面应用程序,我正在测试的应用程序实际上是单页应用程序的集合,通过代理绑定在一起。它给人一种错觉,它是一个大型应用程序,同时保持模块化,更容易迭代。
登录应用时出现问题。 Angular应用程序会将您登录,代理到重定向,并且在此过程中会出现“白色闪烁”,其中不会发生任何事情。正是在这一点上,Protractor调用waitForAngular,它断言在继续之前应用程序中存在一个注射器。
这是事情变得有点奇怪的部分。根据提交日志,a typo in a critical check for an injector可能已阻止在以前版本的Protractor中发生任何问题,因此在升级时,在运行缓慢且有时在浏览器中触发竞争条件的环境中触发此行为。我不太确定。但无论如何,我的登录页面对象中的这段代码有助于解决问题。
login: {
value: function (username, password) {
// normal login code
// by now, it has attempted to log in and redirect, and now...
browser.wait(function () {
return browser.waitForAngular().then(function () {
// injector found, everything is ok
return true;
}, function () {
// if any error occurred, don't throw an exception
// give `.wait` a false result to trigger a retry
return false;
});
}, 10000, 'Injector never appeared after 10 seconds.');
}
}
因此,如果您的系统包含许多通过代理串联在一起的Angular应用程序,那么在您的Protractor测试期间,在CPU速度较慢和/或网络连接有限的环境中,从一个应用程序传递到下一个应用程序时,您会遇到奇怪的错误。 / p>