2014-08-31 70 views
13

我想能夠用量角器測試我的Angular應用程序。由於我使用RequireJS,因此我不能在我的DOM中使用ng-app指令,這就是爲什麼我使用angular.bootstrap手動引導Angular。使用量角器測試與自舉AngularJS

量角器打印錯誤輸出象下面這樣:

Error: Angular could not be found on the page http://localhost:1428/ : retries looking for angular exceeded

然後,我意識到,量角器文檔有一個警告:

Protractor does not work out-of-the-box with apps that bootstrap manually using angular.bootstrap. You must use the ng-app directive.

那麼,有沒有什麼解決辦法運行量角器測試與手動自舉角度應用還是應該開始瞭解其他測試套件?

+0

我們的量角器測試適用於RequireJS和手動引導應用程序。你能分享更多的代碼嗎? :) – glepretre 2014-09-02 06:49:42

回答

13

去量角器confiuration並添加此

onPrepare: function() { 
// implicit and page load timeouts 
    browser.manage().timeouts().pageLoadTimeout(40000); 
    browser.manage().timeouts().implicitlyWait(25000); 

    // for non-angular page 
    browser.ignoreSynchronization = true; 

    // sign in before all tests 

} 

它爲我

我的全配置文件看起來像這樣...

// conf.js 
exports.config = { 
seleniumAddress: 'http://localhost:4444/wd/hub', 
specs: ['../**/*.e2e.js'], 
multiCapabilities: [{ 
browserName: 'firefox' 
}], 

onPrepare: function() { 
// implicit and page load timeouts 
browser.manage().timeouts().pageLoadTimeout(40000); 
browser.manage().timeouts().implicitlyWait(25000); 

// for non-angular page 
browser.ignoreSynchronization = true; 

// sign in before all tests 

} 
} 

實際發生的是,你問從量角器等待一段時間並忽略document.ready(),以便爲您提供手動引導角度的時間。

+0

所以這隻適用於非角度頁面? – 2015-03-17 21:10:08

+0

不是,當你引導角度異步時,這種解決方法也可以工作(我的情況是,我作爲依賴關係從另一個應用程序RequireJS模塊傳遞) – 2015-03-18 10:53:02

+0

這不適用於我,它獲取測試間歇性工作,但其他時間項目不準備好,他們失敗了。 (IE我可以連續運行四次完全相同的測試,並且一次失敗。) – 2015-07-07 17:42:26

相關問題