-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue running protractor #39
Comments
Ok, I managed to wrap the bootstrapping code with browser.ignoreSynchronization = true and set it to false when the test starts. Its a workaround but it works |
I'm seeing the same issue. |
Actually, I think my issue may have been something different. I have raised it here: angular/protractor#4327 |
OK, I think these were the same issue, and I have a solution. The problem is that AngularJS supports "deferred bootstrap". This lets tools like Protractor set a flag on Now, consider the recommended UI Router hybrid bootstrapping code: platformBrowserDynamic().bootstrapModule(SampleAppModule).then(platformRef => {
const injector: Injector = platformRef.injector;
const upgrade = injector.get(UpgradeModule) as UpgradeModule;
upgrade.bootstrap(document.body, ['demo']);
const url: UrlService = injector.get(UrlService);
url.listen();
url.sync();
});
However, because the AngularJS bootstrap is deferred, the call to My solution is to move the myAngularJSModule.run(['$$angularInjector', ($$angularInjector) => {
const url: UrlService = $$angularInjector.get(UrlService);
url.listen();
url.sync();
}]);
And now I'm going to lie down in a dark room for a while until my head stops hurting. |
@jonrimmer Wow! gr8 work... when you get out of the dark room give yourself a pat on the back! |
@jonrimmer You rock! Thanks! |
Ran through this old answer as i was working on this same problem. @artaommahe wrote a super helpful code snippet I modified it to the following: angular.element(document).ready(() => {
deferAndSyncUiRouter(angularJSAppModule); // angularjs module as a variable
platformBrowserDynamic()
// Manually bootstrap the Angular app
.bootstrapModule(AppModule) // Angular module imported from app.module.ts
.then(platformRef => bootstrapWithUiRouter(platformRef, angularJSAppModule));
});
export function deferAndSyncUiRouter(angularjsModule: ng.IModule): void {
angularjsModule
.config([ "$urlServiceProvider", ($urlService: UrlService) => $urlService.deferIntercept()])
.run(["$$angularInjector", $$angularInjector => {
const url: UrlService = getUIRouter($$angularInjector).urlService;
url.listen();
url.sync();
}]);
}
export function bootstrapWithUiRouter(platformRef: NgModuleRef<any>, angularjsModule: ng.IModule): void {
const injector = platformRef.injector;
const upgradeModule = injector.get(UpgradeModule);
upgradeModule.bootstrap(document.body, [ angularjsModule.name ]);
} That got everything working for me. Edit: Also you all may find these imports helpful for the top of your angularjs module file. import * as angular from 'angular';
import {NgModuleRef} from "@angular/core";
import {getUIRouter} from '@uirouter/angular-hybrid';
import {UrlService} from '@uirouter/angular-hybrid/node_modules/@uirouter/angularjs'
import {UpgradeModule} from "@angular/upgrade/static";
import {platformBrowserDynamic} from "@angular/platform-browser-dynamic";
import {AppModule} from "./app.module"; |
I seem to be getting an error while running protractor with angular-hybrid.
Error: Uncaught (in promise): TypeError: Cannot read property \'get\' of undefined
It seems to be coming from:
const url: UrlService = injector.get(UrlService);
where injector is undefined for some reason.
Running browser.ignoreSynchronization = true solves it but breaks our tests.
Any idea why this is?
The text was updated successfully, but these errors were encountered: