問題描述
Protractor 在 Angular 1 上運(yùn)行良好,但在將我的應(yīng)用升級到混合 Angular 1+2 后,我收到此錯誤:
Protractor works well on Angular 1 but after upgrading my app to an hybrid Angular 1+2 I get this error:
失敗:等待 Protractor 與頁面同步時出錯:"[ng:test] 沒有為 getTestability 的元素參數(shù)找到注入器http://errors.angularjs.org/1.4.9/ng/test"
Failed: Error while waiting for Protractor to sync with the page: "[ng:test] no injector found for element argument to getTestability http://errors.angularjs.org/1.4.9/ng/test"
當(dāng)您的 Angular 1 應(yīng)用程序中沒有 ng-app 標(biāo)簽 <div ng-app=myAppManager">
并且可以輕松修復(fù)時,這似乎是一個常見錯誤wiyh rootElement : 'html'
在您的量角器配置文件中,但它似乎沒有改變混合應(yīng)用程序的任何內(nèi)容.
It seems a common error when you don't have a ng-app tag <div ng-app=myAppManager">
in your Angular 1 app and can be easily fixed wiyh rootElement : 'html'
in your protractor config file but it doesn't seem to change anything on hybrid app.
我嘗試了 rootElement : 'html'
甚至 useAllAngular2AppRoots: true
.
我懷疑問題來自混合 Angular 的異步加載(來自 升級文檔):
I suspect the problem comes from the asynchronous loading of the hybrid angular (from the upgrade doc):
angular.bootstrap 和upgradeAdapter.bootstrap 是后者異步工作.這意味著我們不能假設(shè)應(yīng)用程序已經(jīng)實(shí)例化在引導(dǎo)調(diào)用返回后立即.
One notable difference between angular.bootstrap and upgradeAdapter.bootstrap is that the latter works asynchronously. This means that we cannot assume that the application has been instantiated immediately after the bootstrap call returns.
我的配置文件:
exports.config = {
framework: 'jasmine2',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['protractor.js'],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 50000,
},
allScriptsTimeout: 50000,//seb
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'prefs': {
'profile.managed_default_content_settings.notifications':2
}
}
},
rootElement : 'html',
// useAllAngular2AppRoots: true,
jasmineNodeOpts: {
realtimeFailure: true
},
onPrepare: function() {
var failFast = require('jasmine-fail-fast');
jasmine.getEnv().addReporter(failFast.init());
}
}
推薦答案
Protractor 團(tuán)隊(duì)已經(jīng)解決了這個問題:
Protractor team has fixed with this:
https://github.com/angular/angular/pull/7603
我還沒有測試過
編輯 2:似乎不起作用,我回到了 angularJs(版本 1)
編輯 3:我移至 React
這篇關(guān)于量角器 + 混合 Angular 1+2 應(yīng)用程序 = 失敗的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!