protractor: Cannot read property '$$testability' of undefined

In Protractor 5.1.1 if your Angular app has a root element other than <body>, you’ll see the error Cannot read property '$$testability' of undefined. This is because browser.angularAppRoot() is expected to return the current value of app root if a value isn’t passed to it, but currently returns undefined.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 2
  • Comments: 42 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Hi Contributors,

Any updates around this issue . Using protractor version 5.1.2 doesn’t resolve this issue. I have test cases suite that run one after the other and it’s quite sporadic… sometimes it works and sometimes they fail because of this issue. So, if you try to run say ~ 30 cases together , you will still get this issue using 5.1.2.

Thank you for your help.

We’re planning to do a 5.1.2 tomorrow that should include this fix.

I had to add the following code to get rid of

Error: Error while waiting for Protractor to sync with the page: "window.angular is undefined.

browser.ignoreSynchronization = true;
browser.waitForAngular();
browser.sleep(500);
browser.ignoreSynchronization = false;

then had to increase browser.sleep

browser.sleep(5000);

in order to fix

“Cannot read property ‘$$testability’ of undefined”

So it seems like Angular isn’t initialised properly yet

If anyone is still seeing this issue in 5.1.2, could you please reopen with an example that reproduces the problem? Thanks.

@avinashs15 You can build from source by following these directions. After you run npm install you’ll have a binary at bin/protractor that will work with non-body-tag-based AngularJS apps.

Hi - Is this still an issue for some people?

If you are having issues with Protractor and your hybrid app, can you post the following from Chrome devtools console for your app?

  1. window.getAllAngularTestabilities
  2. window.getAngularTestability
  3. window.angular.version

Those who have responded since this issue has been resolved have either:

  1. Had your rootElement defined as body, in which case you have a different problem.
  2. Had your rootElement undefined, meaning it is defaulting to body, in which case you have a different problem.
  3. Have not provided a config.

This issue was specifically related to $$testability being undefined when the rootElement is not the <body> tag, which has been fixed. It is likely you have a different configuration issue.