Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Failed: unknown error: Cannot read property 'get' of undefined / Angular hybrid JIT #4438

Open
Macstyg opened this issue Aug 8, 2017 · 8 comments

Comments

@Macstyg
Copy link

Macstyg commented Aug 8, 2017

Bug report
I've got error while trying to run test on my hybrid 1.6/4.3 angular app.
With others urls this confing below works just as expected, but if I try to run on my app it Failed.

  • Node Version: 8.2.1
  • Protractor Version: 5.1.2
  • Angular Version: 4.3.1/1.6.4
  • Browser(s): chrome=61.0.3163.31
  • Operating System and Version Mac OS X 10.12.6 x86_64
  • Your protractor configuration file
const { SpecReporter } = require('jasmine-spec-reporter');

exports.config = {
  allScriptsTimeout: 20000,
  getPageTimeout: 20000,
  specs: [
    './e2e/**/*.e2e-spec.ts'
  ],
  capabilities: {
    'browserName': 'chrome'
  },
  directConnect: true,
  baseUrl: 'http://localhost:8888',
  framework: 'jasmine',
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    print: function() {}
  },
  onPrepare() {
    require('ts-node').register({
      project: './tsconfig.json'
    });
    jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
  }
};
  • A relevant example test
import { browser, element, by, ElementFinder } from 'protractor';

describe('Protractor Demo App', () => {
  it('should have a title', () => {
    browser.get('');
    expect(browser.getTitle()).toContain('my page title name');
  });
});
  • Output from running the test
**************************************************
*                    Failures                    *
**************************************************

1) Protractor Demo App should have a title
  - Failed: unknown error: Cannot read property 'get' of undefined
    (Session info: chrome=61.0.3163.31)
    (Driver info: chromedriver=2.31.488774 (7e15618d1bf16df8bf0ecf2914ed1964a387ba0b),platform=Mac OS X 10.12.6 x86_64)

Executed 1 of 1 spec (1 FAILED) in 11 secs.
[13:31:30] I/launcher - 0 instance(s) of WebDriver still running
[13:31:30] I/launcher - chrome #01 failed 1 test(s)
[13:31:30] I/launcher - overall: 1 failed spec(s)
[13:31:30] E/launcher - Process exited with error code 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! dps@2.2.7 protractor: `protractor protractor.config.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the dps@2.2.7 protractor script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Process finished with exit code 1```
- Steps to reproduce the bug
- The URL you are running your tests against (if relevant)

@Macstyg
Copy link
Author

Macstyg commented Aug 8, 2017

Seems like adding browser.waitForAngularEnabled(false); in beforeEach block fixed this problem.

@wswebcreation
Copy link
Contributor

Is the first page a non-angular page? Because with your "fix" you are disabling the waiting for Angular.

If it is fixed for you with your provided solution can the issue be closed?

@Macstyg
Copy link
Author

Macstyg commented Aug 9, 2017

My index page is manually bootstrapped AngularJs page with one root component. I don't think this solution is something that can be expected.

@wswebcreation
Copy link
Contributor

Do you have an example project?

@Macstyg
Copy link
Author

Macstyg commented Aug 9, 2017

My index file:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport"
        content="width=device-width, initial-scale=1">
  <title>App</title>
  <base href="/">
</head>
<body>
<app>
  Loading...
</app>
</body>
</html>

app component:

template: `<ng2root></ng2root><div data-ui-view></div>

botstrap:

document.addEventListener("DOMContentLoaded", () => {
  platformBrowserDynamic().bootstrapModule(AppModule).then(platformRef => {
    const injector: Injector = platformRef.injector;
    const upgrade = injector.get(UpgradeModule) as UpgradeModule;
    upgrade.bootstrap(document.body, [ng1App.name], {strictDi: true});
    const url: UrlService = injector.get(UrlService);
    url.listen();
    url.sync();
  });
});

@wswebcreation
Copy link
Contributor

Hi @Macstyg

I was more looking for an example project on Github where I can look at the testcode and try to debug it for you. Is that possible?

@Macstyg
Copy link
Author

Macstyg commented Aug 16, 2017

Hi @wswebcreation
I'm sorry, but this is large commercial project, and I can't share it.
And after some upgrades in one of starters page without browser.waitForAngularEnabled(false)
protractor start to throw this error:
- Failed: Error while waiting for Protractor to sync with the page: "Cannot read property '$$testability' of undefined".
I see there is already been issue #4233

@wswebcreation
Copy link
Contributor

@Macstyg

Did you also took a look at this regarding Zone? It's suggested by the Protractor team, but there are also some issues with it (not being able to use for example the localStorage), but it's worth a try i guess.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants