2016-06-28 31 views
1

我正在使用量角器在網站上自動執行一些測試。 在angular和所有其他腳本和css加載之後,會有一個引用的第三方資源需要很長時間才能加載。量角器等待資源完成加載時,由於超時,單元測試失敗。 有幾種方法可以在幾秒鐘後跳過加載資源並繼續執行任務。 (PS:增加超時限制是解決不了問題對我來說)如果響應時間過長,則將量角器配置爲忽略資源

it('abc', function() { //This is fine browser.driver.get('http://loginurl.com'); browser.driver.findElement(by.name('username')).sendKeys('username'); browser.driver.findElement(by.name('password')).sendKeys('password'); browser.driver.findElement(by.name('loginsubmit')).click(); browser.sleep(3000); //This has problems browser.driver.get('http://contenturl.com'); browser.sleep(1000); browser.executeScript("window.stop();"); browser.driver.findElement(by.id('post_reply')).click(); browser.sleep(1000); browser.driver.findElement(by.id('postmessage')).sendKeys('aaabbbcc'); browser.driver.findElement(by.id('postsubmit')).click(); browser.pause(); //browser.get('http://url.com'); //element(by.id("post_replytmp")).click(); });

回答

0

您可以在頁面加載超時執行window.stop()

browser.get("url", 10000).then(function() {}, function() { 
    browser.executeScript("window.stop();"); 
}); 

(未測試)。

+0

對我而言,除非頁面完全加載,否則此行不會執行。我的代碼是 'browser.driver.get('url'); browser.sleep(3000); browser.executeScript(「window.stop();」);' –

+0

@maxiC啊,gotcha。你能否請嘗試更新版本的答案?謝謝! – alecxe

+0

謝謝。它似乎仍在等待頁面完成。我會挖掘更多。再次感謝! –