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

Gre*_*rty 14 jasmine angularjs protractor

我正在尝试针对我自己的AngularJS代码运行本教程.我无法通过第一次测试.任何从我的页面提取任何信息的尝试都会收到此错误:

     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()
Run Code Online (Sandbox Code Playgroud)

Does anyone have a Protractor tutorial that shows you how to target your own code, rather than someone else's code?

Thank you in advance

小智 25

就像接受的答案所暗示的那样,问题在于让量角器知道应用程序的根源是什么,这就是定义ng-app的地方.默认情况下,这应该是标记,但您的代码似乎在其他地方.不过,您实际上可以在配置文件中更改该行为.

从Protractor 参考配置文件:

  // CSS Selector for the element housing the angular app - this defaults to
  // body, but is necessary if ng-app is on a descendant of <body>.
  rootElement: 'body',
Run Code Online (Sandbox Code Playgroud)

例如,如果你的ng-app在这样的div中:

<div id="my-app" ng-app=myAppManager">

你可以用

rootElement: '#my-app'

由于它是一个CSS选择器,您还可以使用方括号语法来按属性选择,如下所示:

rootElement: '[ng-app]'

这将选择包含属性ng-app的元素,无论它是哪一个.


Gre*_*rty 6

答案是你必须拥有<html ng-app><html ng-app = "">在你的html页面的顶部才能使用Protractor.

<div ng-app = "">例如,将应用程序作为a的一部分将不起作用

  • 如果在protractor.config.js中设置rootElement:"[ng-app]",它将起作用 (11认同)
  • 但请注意,将ng-app放在<body>标签上会起作用. (4认同)