Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i supply "rootelement" option while testing protractor interatively

When I execute node elementexplorer.js http://127.0.0.1:8080/app/view1

I get the following error:

There was a webdriver error: 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."

Please let me know how to provide the rootelement option.

like image 947
abdulla syed Avatar asked Mar 03 '15 15:03

abdulla syed


2 Answers

At the moment, rootElement defaults to body. If you don't have your ng-app in the body, you will get that error. It can be set manually tho.

You need to change the rootElement. You can do it directly from the interactive view by running:

browser.rootEl = 'div#ng-app-located-here';

Assuming that your ng-app is located at div#ng-app-located-here

like image 88
Julio Avatar answered Oct 19 '22 23:10

Julio


In this case, you need to specify on which element your ng-app is set. Add rootElement in your protractor conf.js, for example:

rootElement: 'div#nested-ng-app'  // by default, it is 'body'

FYI, this is because protractor angular-specific custom locators, like by.binding or by.model use rootElement as a root for the search, quote from the change log:

Protractor's custom locators (by.binding, by.model, etc) use config.rootElement as the root for all their searches. This meant that config.rootElement was used both to specify how to get hold of Angular's injector as well as where to begin searching for elements. This does not work for all cases, for example if a dialog should be searched for elements but is a sibling, not a child, of ng-app.

like image 41
alecxe Avatar answered Oct 19 '22 23:10

alecxe