3
我有一個應用程序在單擊按鈕時啓動$超時,所以我必須使用ignoreSynchronization設置爲true。在此期間,我需要等待元素添加到頁面,並且在等待過程中遇到了一些有趣的行爲:量角器在忽略同步期間等待,瀏覽器隱式超時vs browser.wait超時
browser.wait(元素,超時,錯誤消息)期間傳遞的等待超時沒有。唯一重要的是等待在瀏覽器上設置的隱式超時。最重要的是,將使用ENTIRE隱式超時。如果發現元素存在,它將繼續檢查直到超時結束。這意味着測試將始終以最大時間緩慢運行。
describe('Cool Page',() =>{
beforeEach(function(){
browser.ignoreSynchronization = true;
return browser.sleep(250);
});
afterEach(function(){
browser.ignoreSynchronization = false;
return browser.sleep(250);
});
it('can open menu with timeout', function(){
// No timeout at this point
coolPage.wait.ellipsesIcons().then(() =>{
// Clicking the ellipses icons kicks off a $timeout of 100 seconds
coolPage.ellipsesIcons.click().then(() =>{
coolPage.wait.dropdownOptions().then(() => {
expect(coolPage.dropdownOptions.getText()).toContain('Option 1');
});
});
});
});
})
。
export = new CoolPage;
class CoolPageextends PageObject {
private elements;
constructor(){
super();
... // Lots of other stuff
this.initWait();
}
... // Initializing elements and other things
private initWait() {
this.wait = {
ellipsesIcons:() => {
// Timeout of 5 seconds will be used - regardless of isPresent resolving as true or false, the entire 5 seconds will be used
browser.manage().timeouts().implicitlyWait(5000);
// The 2 milliseconds passed in here does nothing at all
browser.wait(element(by.css('.fa-ellipses-h')).isPresent(), 2, 'Ellipses Icon(...) was not present in time');
// Must reset implicit wait back to the original 25 seconds it was set too in the conf
browser.manage().timeouts().implicitlyWait(25000);
return browser.sleep(150);
},
dropdownOptions:() => {
// This two seconds wait WILL be used
browser.manage().timeouts().implicitlyWait(2000);
// This five second wait WILL NOT be used
browser.wait(element(by.css('[name="change-status"]')).isPresent(), 5000, 'Options actions menu item was not present in time');
browser.manage().timeouts().implicitlyWait(25000);
return browser.sleep(150);
},
}
}
通過browser.wait傳入的超時在這裏沒有效果。我的問題是:
- browser.wait timeout有什麼作用?
- 何時使用隱式等待?我認爲這只是等待頁面加載
- 有沒有什麼辦法可以在實際使用的超時時間內傳遞?
- 如果不是,只要條件滿足,是否有任何方法讓等待退出,而不是使用整個超時?