找不到getTestability的元素参数的注入器

时间:2015-01-20 07:47:08

标签: angularjs jasmine protractor

我正在尝试对我自己的AngularJS代码运行this tutorial。我无法通过第一次测试。任何从我的页面中提取任何信息的尝试都会出现此错误:

     Error: Error while waiting for Protractor to sync with the page: "[ng:test] no injector found for element argument to getTestability\nhttp://errors.angularjs.org/1.3.8/ng/test"
   Stacktrace:
     Error: Error while waiting for Protractor to sync with the page: "[ng:test] no injector found for element argument to getTestability\nhttp://errors.angularjs.org/1.3.8/ng/test"
    at Error (<anonymous>)
==== async task ====

Protractor.waitForAngular()
==== async task ====
Asynchronous test function: it()

有没有人有一个Protractor教程,向您展示如何定位自己的代码,而不是别人的代码?

提前谢谢

4 个答案:

答案 0 :(得分:6)

答案是您必须在html页面的顶部放置<html ng-app><html ng-app = "">才能使用量角器。

例如,将应用作为<div ng-app = "">的一部分,将无效

答案 1 :(得分:2)

我的角度自举代码如下:

var appName = "testApp";
var appContainer = document.getElementById('app-container');
angular.bootstrap(appContainer, [appName]);

我得到了同样的错误,并且我从@jgiralt那里得到了建议,这是修正此错误的量角器的conf.js:

// conf.js
exports.config = {
  framework: 'jasmine',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  rootElement: '#app-container',
  specs: ['spec.js']
}

答案 2 :(得分:0)

我在使用茉莉和量角器进行E2E测试时遇到了同样的问题。

这与root html标签有关。

在量角器运行时,我收到了错误..
“等待量角器与页面同步时出错:”[ng:test]未找到进样器 for getTestability的元素参数\ nhttp://errors.angularjs.org/1.3.13/ng/test“

为了解决这个问题,我在root html标签中做了一个小改动 通过输入 lang =“en”属性。 这解决了我的问题。

最终HTML

<!DOCTYPE html> <html lang="en" ng-app="test"> ..... </html>

我希望这会对你有所帮助。

感谢。

答案 3 :(得分:0)

您可能有一个不相关的角度注入器错误,导致量角器输出。尝试清理终端,再次运行量角器,并查看详细量角器输出上方显示的第一个错误。如果是角度注入器错误,您可以通过向index.html添加脚本标记来修复它。

终端输出:
Error: [$injector:modulerr] Failed to instantiate module app.components.slider

可以通过在index.html中添加以下内容来修复:
<script src="app/components/sliders/slider.component.js"></script>

这是有效的,因为模块app.components.slider在文件app/components/sliders/slider.component.js中定义。它可能在合并/ rebase期间意外地从您的index.html文件中删除,或者从未添加到首位。

相关问题