2015-10-05 57 views
1

我想從我的網站測試一個基本的登錄/註銷。我的角度應用程序的入口點來自非角度登錄頁面(oauth),然後在驗證憑據後爲應用程序提供服務。我的測試將在本地運行,但不會在Circle Ci上運行;我的錯誤是這樣的;從無角度登錄頁面的量角器測試

Message: 
    Failed: Error while waiting for Protractor to sync with the page: "angular could not be found on the window" 
    Stack: 
Error: Failed: Error while waiting for Protractor to sync with the page: "angular could not be found on the window" 

這裏是我的測試功能:

it('Log into Webapp', function() { 
    browser.ignoreSynchronization = true; 
     browser.manage().timeouts().pageLoadTimeout(40000); 
     browser.manage().timeouts().implicitlyWait(25000); 

     browser.get('http://localhost:8000/login'); 

     element(by.id('username')).sendKeys('x..'); 
     element(by.id('password')).sendKeys('...'); 
     element(by.name('Login')).click(); 

     setTimeout(function(){}, 15000); 
     element(by.name('save')).click(); 

     setTimeout(function(){}, 10000); 
     //browser.waitForAngular(); 
     //browser.ignoreSynchronization = false; 
     //browser.ignoreSynchronization = false; 
     // Angular app should be served, Logout is on this 
     browser.ignoreSynchronization = false; 

     element(by.name('logoutBtn')).click(); 

}); 

回答

4

嘗試移動ignoreSynchronizationbeforeEachafterEach

beforeEach(function() { 
    browser.ignoreSynchronization = true; 
}); 

afterEach(function() { 
    browser.ignoreSynchronization = false; 
}); 

幫我解決:Non-angular page opened after a click

+1

一個真正的非Angular網站可能可能會瀏覽器.ignoreSynchronization移到beforeAll並沒問題,但這是一個非常好的起點。 – MBielski

+0

@alecxe但beforeEach會影響角度規格('it'),對吧?如果測試套件中有任何一個('describe')。 –

+0

@GirishSortur是的,這可能會成爲一個問題,讓我們來看看OP會說些什麼,謝謝! – alecxe

1

用browser.sleep(10000)替換setTimeout調用;

setTimeout在超時後執行回調函數,但主「線程」繼續其執行流程。所以你並不是真的在等待。

此外,您可以在最後一次logoutBtn單擊之前使用browser.waitForAngular()。

像這樣:

it('Log into Webapp', function() { 
    browser.ignoreSynchronization = true; 
    browser.manage().timeouts().pageLoadTimeout(40000); 
    browser.manage().timeouts().implicitlyWait(25000); 

    browser.get('http://localhost:8000/login'); 

    element(by.id('username')).sendKeys('x..'); 
    element(by.id('password')).sendKeys('...'); 
    element(by.name('Login')).click(); 

    browser.sleep(15000); 
    element(by.name('save')).click(); 

    browser.sleep(10000); 
    browser.waitForAngular();   

    element(by.name('logoutBtn')).click(); 

    // Angular app should be served, Logout is on this 
    browser.ignoreSynchronization = false; 

});

+0

在測試代碼中引入睡眠命令不是不好的做法嗎? 當您在測試周期中混合使用這些顯式的睡眠時,您最終會浪費時間,或者有時沒有足夠的等待時間 因爲您必須等待,即使您在頁面上查找的內容已經存在,或者睡眠時間不夠長,這打破了你的測試 – Dror

+0

是的,我完全同意,但如果這個人使用睡眠呼叫,他應該使用'browser.sleep()',而不是'setTimeout'。 – hhaamm

相關問題