Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No injector found for element argument to getTestability

I'm trying to run this tutorial against my own AngularJS code. I can't get past the first test. Any attempt to pull any information from my page gets this error:

     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()

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

like image 958
Greg Dougherty Avatar asked Jan 20 '15 07:01

Greg Dougherty


3 Answers

Like the accepted answer implies, the problem lies in letting protractor know what's the root of your app, this is where ng-app is defined. By default this is expected to be the tag but your code seems to have it somewhere else. Nevertheless you can actually change that behavior in the config file.

From the Protractor reference config file:

  // 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',

For example, if your ng-app is within a div like this:

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

You could use

rootElement: '#my-app'

Since it's a CSS selector, you could also use the square brackets syntax to select by attribute, like this:

rootElement: '[ng-app]'

This would select the element that contains the attribute ng-app, no matter which one it is.

like image 144
jgiralt Avatar answered Nov 19 '22 07:11

jgiralt


The answer is that you must have <html ng-app> or <html ng-app = ""> at the top of your html page in order to use Protractor.

Having an app as part of a <div ng-app = "">, for example, will not work

like image 31
Greg Dougherty Avatar answered Nov 19 '22 08:11

Greg Dougherty


I have my angular bootstrapping code as below:

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

I got the same error that you got and with the advice that I took from @jgiralt, here is my conf.js of protractor that fixed this error:

// conf.js
exports.config = {
  framework: 'jasmine',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  rootElement: '#app-container',
  specs: ['spec.js']
}
like image 2
randominstanceOfLivingThing Avatar answered Nov 19 '22 06:11

randominstanceOfLivingThing