2014-12-06 33 views
8

我有一個引導的Angular(1.2.6)應用程序。這意味着它沒有明確的ng-app。因此,我遇到了讓Protractor框架的測試工作的各種問題(使用SauceLabs和grunt-protractor-runner)。量角器:如何等待自舉的AngularJS的滿負荷

的錯誤基礎是什麼我嘗試改變,但一般:

Error: Angular could not be found on the page http://xxx:9000/ : 
angular never provided resumeBootstrap 

或者......

Error: Error while waiting for Protractor to sync with the page: {} 

,我發現了一些建議的解決方案,我試過。包括在this rich thread中找到的那些,以及here。儘管如此,我沒有做任何事情。

我試着使用angular.resumeBootstrap在引導像這樣(注意我試過的這種多變化都無濟於事,包括試圖在文檔正文編程設定NG-APP):

angular.element(document).ready(function() { 
    window.name = 'NG_DEFER_BOOTSTRAP!' 
    angular.bootstrap(document, [ 'app' ]); 
    setTimeout(angular.resumeBootstrap, 0); 
}); 

這樣做的錯誤,正如其他人發現的,是怪異:

UnknownError: unknown error: [ng:btstrpd] App Already Bootstrapped with this Element 
'<body ng-app="" ng-controller="ApplicationController" class=" ng-scope pace-done">' 

什麼奇怪/可氣的是,至少在尋找醬實驗室會議,看來這個測試工作...它只是古怪思想,它被引導了兩次。

我也試過在測試本身中使用waitForAngular,wait和其他的各種組合。這裏有一個變化我已經試過:

it('should load the home page', function() { 
    ptor = protractor.getInstance(); 
    ptor.waitForAngular(); 
    ptor.driver.get('http://xxx:9000/'); 
    ptor.driver.wait(function() { 
    return ptor.getCurrentUrl().then(function() { 
     return ptor.isElementPresent(by.id('signIn')).then(function() { 
     console.log('we are here!'); 
     return true; 
     }); 
    }); 
    }) 
    .then(function() { 
    expect(ptor.isElementPresent(by.id('signIn'))).toBe(true); 
    }); 
}); 

這導致類似下面的錯誤:

1) e2e: home should load the home page 
    Message: timeout: timed out after 20000 msec waiting for spec to complete 
    Stacktrace: undefined 

我也試過在配置文件無濟於事增加各種超時。

任何幫助將不勝感激!

+0

@alecxe'grunt-protractor-runner @ 1.1.4'和'protractor @ 1.4.0'。我正在運行更早的版本,升級(認爲會有所幫助)...並且沒有(明顯的)差異。 – pjb 2014-12-06 06:44:06

+0

我不確定這會有幫助,但可以嘗試將量角器降級到早期版本。 – alecxe 2014-12-06 06:46:33

+0

@alecxe耶,以前正在嘗試'量角器@ 0.24.2'(!)和相同的結果。 – pjb 2014-12-06 07:11:02

回答

3

你應該在兩個'it'-steps中分開測試。像這樣:

it('should load angular', function() { 
    ptor = protractor.getInstance(); 
    ptor.waitForAngular(); 
}) 

it('should load the home page', function() { 
    ptor.driver.get('http://xxx:9000/'); 
    ptor.driver.wait(function() { 
    return ptor.getCurrentUrl().then(function() { 
     return ptor.isElementPresent(by.id('signIn')).then(function()  { 
     console.log('we are here!'); 
     return true; 
     }); 
    }); 
    }) 
    .then(function() { 
    expect(ptor.isElementPresent(by.id('signIn'))).toBe(true); 
    }); 
}); 

量角器的問題在於,每個命令都會在不等待上一步完成的情況下運行。所以,ptor.waitForAngular()ptor.driver.get('http://xxx:9000/')幾乎同時運行。如果將這些分成兩步,量角器在完成第一個「it」步驟後繼續運動。

+0

我忘了提及protrator.getInstance()已被棄用。使用瀏覽器,而不是https://github.com/angular/protractor/blob/master/CHANGELOG.md#breaking-changes-1 – apoh 2015-02-19 15:36:15

+0

這對我使用require.js手動引導的應用程序的工作。我把browser.waitForAngular()放在前體「it」塊中,並在我的量角器conf文件中設置browser.ignoreSynchronization = true。這看起來很不舒服,但它工作。唷。 – 2015-07-06 22:17:50

+2

更正,這隻適用於我*部分時間*。非常令人沮喪,我仍然在完全相同的測試中得到間歇性錯誤。 – 2015-07-07 17:44:14