我有一个应用程序,当一个按钮被点击时,它会启动一个$timeout,所以我必须将ignoreSynchronization设置为true。在此期间,我需要等待元素被添加到页面中,在等待过程中我经历了一些有趣的行为:
浏览器期间传入的等待超时。wait(元素、超时、错误消息)不起作用。唯一重要的等待是浏览器上设置的implicitTimeout。除此之外,还将使用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传入的超时在这里不起作用。我的问题是:
尝试在浏览器等待中使用预期条件。看看它('应该等待一系列周期性增量'
,以使用函数textToBePresentInElement
为例。为了检查元素是否存在,我可能会尝试 visibility Of
或 presenceOf
。