2014-12-04 53 views
1

我有一個量角器測試,導航到另一個URL,在我的測試環境中無法找到/解析,所以我檢查標題是否不是以前的標題。如何等待元素不再存在

測試如下:

it('should navigate to another site in case of click on cancel link', function() { 
    page.navigate(); 
    page.submit(); 
    protractor.getInstance().ignoreSynchronization = true; 
    browser.wait(function(){ 
     return element(by.id('submit')).isPresent(); 
    }); 
    page.closePage(); 
    // the title of a 404, dns issue etc is at least different from the previous site: 
    expect(browser.getTitle()).not.toEqual('MyDummyTitle') 
    protractor.getInstance().ignoreSynchronization = false; 
}); 

這在大多數的瀏覽器,但在Internet Explorer中我發現,它往往是沒有準備好導航到不存在的頁面,就會引發期待。

我可以以某種方式等待'submit'元素消失,類似於我在執行closePage之前做的事情嗎?

回答

1

我在此情況下,做的是一個active wait of an element to disappear

使用積極等待一個元素,無論是成爲無形的或不存在消失的自定義waitAbsent()助手功能。

該幫手等到specTimeoutMs忽略像StaleElementError這樣無用的web驅動程序錯誤。

用法:在您的onPrepare區塊或文件中添加require('./waitAbsent.js');

例等待#submit將消失:

expect(element(by.id('submit')).waitAbsent()).toBeTruthy(); 
+1

的感謝!奇蹟般有效。 – Maarten 2014-12-09 10:17:05