Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve rootElement default #1742

Closed
juliemr opened this issue Jan 20, 2015 · 18 comments
Closed

Improve rootElement default #1742

juliemr opened this issue Jan 20, 2015 · 18 comments

Comments

@juliemr
Copy link
Member

juliemr commented Jan 20, 2015

At the moment, rootElement defaults to body, which is not particularly smart. It can be set manually, but we can improve the experience here.

@sjelin
Copy link
Contributor

sjelin commented Jan 21, 2015

If we're willing to make undefined a special case we could have the default be:

  • Look for [ng-app], [ng:app], and if exactly one result is found use that
  • Otherwise, use body (or maybe throw an error?)

@galxy25
Copy link

galxy25 commented Jan 21, 2015

Whoa, I was just about to open an issue on this topic, good to see this is something the protractor team is looking into.

I sporadically get errors like:

Error: Error while waiting for Protractor to sync with the page: "root element (body) has no injector. this may mean it is not inside ng-app."
Stacktrace:
Error: Error while waiting for Protractor to sync with the page: "root element (body) has no injector. this may mean it is not inside ng-app."
at Error ()
==== async task ====
Protractor.waitForAngular()
at [object Object]. (/home/ubuntu/skraphaug/angular/test/e2e/home_page_spec.js.coffee:39:37)
==== async task ====
Asynchronous test function: it()
Error
at [object Object]. (/home/ubuntu/skraphaug/angular/test/e2e/home_page_spec.js.coffee:38:7)
at [object Object]. (/home/ubuntu/skraphaug/angular/test/e2e/home_page_spec.js.coffee:28:5)
at Object. (/home/ubuntu/skraphaug/angular/test/e2e/home_page_spec.js.coffee:6:3)
at Object. (/home/ubuntu/skraphaug/angular/test/e2e/home_page_spec.js.coffee:127:4)
at Object.loadFile (/home/ubuntu/skraphaug/angular/node_modules/coffee-script/lib/coffee-script/register.js:16:19)
at require (module.js:380:17)
at Function.promise (/home/ubuntu/nvm/v0.10.33/lib/node_modules/protractor/node_modules/q/q.js:650:9)
at _fulfilled (/home/ubuntu/nvm/v0.10.33/lib/node_modules/protractor/node_modules/q/q.js:797:54)
at self.promiseDispatch.done (/home/ubuntu/nvm/v0.10.33/lib/node_modules/protractor/node_modules/q/q.js:826:30)
at Promise.promise.promiseDispatch (/home/ubuntu/nvm/v0.10.33/lib/node_modules/protractor/node_modules/q/q.js:759:13)
at /home/ubuntu/nvm/v0.10.33/lib/node_modules/protractor/node_modules/q/q.js:525:49
at flush (/home/ubuntu/nvm/v0.10.33/lib/node_modules/protractor/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:419:13)

While for us, our homepage declares ng-app on the html tag,

Which lead me to this thread on SO
http://stackoverflow.com/questions/20059943/running-into-error-while-waiting-for-protractor-to-sync-with-the-page-with-basic

Would you suggest just adding root-element of html in my conf.js file? Why is it that the majority of the time protractor doesn't throw this error, when the default root element is body but that is not where I have set my ng-app at.

@sjelin
Copy link
Contributor

sjelin commented Jan 21, 2015

If body is not the root element of your ng-app, you should specify what element is in your conf.js, yes

@galxy25
Copy link

galxy25 commented Jan 21, 2015

@sjelin thanks, I've specified rootElement: 'html' now in my cont.js file, just extremely curious as to why protractor 90% of the time never complained that it was looking for the rootElement on body, with my ng-app being defined on html

@sjelin
Copy link
Contributor

sjelin commented Mar 6, 2015

Please ask questions like this on stack overflow. (Also I think that angular isn't loading properly)

@Droogans
Copy link

Droogans commented Mar 6, 2015

@sjelin I think I've got a fix that works. I'll post (and answer) a stackoverflow question and delete this.

EDIT: http://stackoverflow.com/questions/28908878/protractor-tests-find-no-injector-in-my-app-but-only-on-jenkins

@juliemr juliemr modified the milestone: Upcoming Mar 17, 2015
@henrahmagix
Copy link

+1 for looking for [ng-app], [ng:app] and defaulting to body if 0 or >1 results found.

@henrahmagix
Copy link

I've set rootElement: 'html' but I still get the error in a test that involves a redirect/reload not triggered by the control flow. I posted detailed information on http://stackoverflow.com/questions/30783518/protractor-test-sometimes-fails-when-reloading-angular-app

@Javilete
Copy link

Hello, I have been reading about this issue that randomly, my protractor test is failing because of the same error mentioned above (Error while waiting for Protractor to sync with the page: "root element (body) has no injector. this may mean it is not inside ng-app.) Is there a solution there that guarantees consistency? My application does the bootstrapping manually, so the ng-app is set to body but sometimes I get this error. I have tried to set rootElement: 'html' but the tests fail sometimes. Can you please advise guys if you have found a solution for this? Thanks in advance.

@sjelin
Copy link
Contributor

sjelin commented Mar 15, 2016

Please ask support questions on stack overflow. Also, you probably want rootElement: 'body'

@Javilete
Copy link

Ok, thanks!

@keithrz
Copy link

keithrz commented Mar 24, 2016

I updated to Protractor 3.2.1, and I get the following error:
Error while waiting for Protractor to sync with the page: "window.angular is undefined.  This could be either because this is a non-angular page or because your test involves client-side navigation, which can interfere with Protractor's bootstrapping.  See http://git.io/v4gXM for details"

ng-app is on html tag, and there is an ng-controller directive on the body tag.

I tried setting rootElement: 'html', but that did not seem to make a difference.

I did not get this error in Protractor 3.1.1

@sjelin
Copy link
Contributor

sjelin commented Mar 24, 2016

Does your test involve a non-angular page? Or client-side navigation (i.e. clicking on a link)? Did you check the URL for details?

@keithrz
Copy link

keithrz commented Mar 24, 2016

The test does not involve a non-angular page. By client-side navigation, I'm confused. Do you mean navigation that uses ng routing? i.e. we are using angular-ui-router, so the only links we have keep the user on the same page, just a different path after the /#/

But those links are everywhere in our app, and we need to test them in our automated tests. And the confusing part about the link is:

  • issue is closed
  • description says to just add a better error message

The workaround seems to be calling browser.refresh() after clicking on a link - does that actually add another browser refresh in this instance? It seems like a risky workaround.

I guess I should be adding this info to that (closed) issue, but I thought that it had more to do with my rootElement being in the html tag, and controller in the body tag. And I could not recreate in 3.1.1, only 3.2.1.

I also tried the workaround mentioned in the link below, but that did nothing:
http://stackoverflow.com/questions/34600052/protractor-throwing-error-now-that-ng-app-directive-is-on-html-tag

workaround I tried: rootElement: '[ng-app="ourApp"]'

Hey, thanks for the quick response! Protractor is amazing, but it is really hard keeping up with browser and selenium versions. New stuff keeps coming in and breaking everything!!

@sjelin
Copy link
Contributor

sjelin commented Mar 28, 2016

If the links never cause a page to unload then it's not a client-side navigation problem (probably). Could you get me a small reproduction of this problem? Preferably in a small github repo? And make a separate issue for it (since this is a discussion not a bug report)?

@keithrz
Copy link

keithrz commented Mar 30, 2016

Sorry for my messages, please disregard them. I was using gulp-protractor, and assumed that it was using protractor as a peer dependency. My issue is related to my own setup; nothing with protractor itself.

@juliemr
Copy link
Member Author

juliemr commented Jul 14, 2016

This is also going to become interesting as Angular2 hits, where we have no ng-app helper. I'm not sure there's much we can do there. But we can still help out for 1.5.

@sjelin
Copy link
Contributor

sjelin commented Dec 20, 2016

Pending and version 5.0, we'll be changing this to the following:

  • config.rootElement now defaults to ''
  • If you are an ng2 app, '' is equivalent to useAllAngular2AppRoots
  • If you are an ng1 app, and you are using version ~1.3.12 or >=1.4.0-beta.3 of angular.js, '' defaults to the element you bootstrap to.
  • If you are an ng1 app, and you are using an older version of angular.js, we will automatically search for injectors in <body> and elements tagged with either ng-app or ng-controller.

This should find your root element almost all the time.

sjelin added a commit to sjelin/protractor that referenced this issue Dec 20, 2016
sjelin added a commit to sjelin/protractor that referenced this issue Dec 20, 2016
sjelin added a commit to sjelin/protractor that referenced this issue Dec 21, 2016
sjelin added a commit to sjelin/protractor that referenced this issue Dec 21, 2016
sjelin added a commit to sjelin/protractor that referenced this issue Dec 21, 2016
sjelin added a commit to sjelin/protractor that referenced this issue Dec 21, 2016
sjelin added a commit to sjelin/protractor that referenced this issue Dec 21, 2016
sjelin added a commit to sjelin/protractor that referenced this issue Dec 21, 2016
sjelin added a commit to sjelin/protractor that referenced this issue Dec 22, 2016
@sjelin sjelin self-assigned this Dec 22, 2016
sjelin added a commit to sjelin/protractor that referenced this issue Dec 27, 2016
This is a breaking change because it changes the default root element behavior
and removes the `config.useAllAngular2AppRoots` flag.  Modern angular apps now
default to using all app hooks, and ng1 apps now check several places, notably
the element the app bootstraps to.

Closes angular#1742
sjelin added a commit to sjelin/protractor that referenced this issue Dec 28, 2016
This is a breaking change because it changes the default root element behavior
and removes the `config.useAllAngular2AppRoots` flag.  Modern angular apps now
default to using all app hooks, and ng1 apps now check several places, notably
the element the app bootstraps to.

Closes angular#1742
sjelin added a commit to sjelin/protractor that referenced this issue Jan 3, 2017
This is a breaking change because it changes the default root element behavior
and removes the `config.useAllAngular2AppRoots` flag.  Modern angular apps now
default to using all app hooks, and ng1 apps now check several places, notably
the element the app bootstraps to.

Closes angular#1742
sjelin added a commit to sjelin/protractor that referenced this issue Jan 3, 2017
This is a breaking change because it changes the default root element behavior
and removes the `config.useAllAngular2AppRoots` flag.  Modern angular apps now
default to using all app hooks, and ng1 apps now check several places, notably
the element the app bootstraps to.

Closes angular#1742
sjelin added a commit that referenced this issue Jan 3, 2017
…er (#3849)

This is a breaking change because it changes the default root element behavior
and removes the `config.useAllAngular2AppRoots` flag.  Modern angular apps now
default to using all app hooks, and ng1 apps now check several places, notably
the element the app bootstraps to.

Closes #1742
@sjelin sjelin closed this as completed in bc58332 Jan 4, 2017
AlexVotry pushed a commit to AlexVotry/bikerack that referenced this issue Mar 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants