Protractor fails when app is bootstrapped with ngUpgrade
See original GitHub issueI am working on migrating an AngularJS (1.6) app to Angular (4) and now have a hybrid application, bootstrapped with NgUpgrade. This seems to have completely broken my Protractor tests.
Forgive me if this is just something I am doing wrong, but I can’t find any answer as to why this won’t work.
The error I get is:
Failed: Timed out waiting for asynchronous Angular tasks to finish after 11 seconds. This may be because the current page is not an Angular application. Please see the FAQ for more details: https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular
While waiting for element with locator - Locator: By(css selector, .toggle-summary-button)
Hybrid app changes
The application seems to run fine, and both AngularJS and Angular components are working as expected. The changes I made in the bootstrapping process are:
1 Removed ng-app from html tag:
<html lang="en" *ng-app="myapp">
2 Added an AppModules (@NgModule) etc.
3 Used NgUpgrade to bootstrap the app:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { UpgradeModule } from '@angular/upgrade/static';
import { AppModule } from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule).then(platformRef => {
const upgrade = platformRef.injector.get(UpgradeModule) as UpgradeModule;
upgrade.bootstrap(document.body, ['myapp'], {strictDi: true});
});
Protractor tests
Based on the error above, the problem seems to be related to whatever Protractor does when it is waiting for Angular. I have a beforeEach block which loads the login page, fills in the details and logs in. Weirdly it is still opening the page and entering text into the username field, but then it fails to go any further.
I have tried, with no success:
- adding “rootElement: ‘body’” to my protractor config file
- adding “ng12Hybrid: true” to my protractor config file - I get a message saying that it should no longer be needed as it auto detects.
- increasing the allScriptsTimeout setting from 11000 to 60000 and it still times out.
- turning off the waitForAngularEnabled setting. This solves the problem with the login fields, but then none of my http mocks work and the tests fail.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:13
- Comments:51 (10 by maintainers)
Top GitHub Comments
Hi - we are working on a change to let you configure which tasks Protractor waits for, that can help you handle the above issue. This is a broad change involving Zone.js and Angular and don’t have specific ETA(will be in the order of weeks). Will update on progress here.
From: Castaway(s?) on Island of AngularJS stranded by Protractor Issue #4290 To: @vikerman @juliemr
Ahoy! Could we get an update on this issue? Last update on Oct 16 was an ETA in the “order of weeks”. Or, please close this issue so we can move on.
These are the rafts I’m currently considering:
waitForAngularEnabled(false)
for all tests as suggested by @vladotesanovic. I’m skeptical of this for an entire app but I haven’t tested it. I usewaitForAngularEnabled
in only one situation now and only for a very specific case.