angular / protractor

E2E test framework for Angular apps
http://www.protractortest.org
MIT License
8.75k stars 2.31k forks source link

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

Open Macstyg opened 7 years ago

Macstyg commented 7 years ago

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.

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

1) Protractor Demo App should have a title

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```

Macstyg commented 7 years ago

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

wswebcreation commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

Do you have an example project?

Macstyg commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 https://github.com/angular/protractor/issues/4233

wswebcreation commented 7 years ago

@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.