我有一个应用程序在单击按钮时启动$ timeout,因此我必须将ignoreSynchronization设置为true。在此期间,我需要等待将元素添加到页面中,并且在等待期间我遇到了一些有趣的行为:
在browser.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传递的超时对此没有影响。我的问题是:
答案 0 :(得分:0)
尝试在浏览器等待时使用expected conditions。使用函数textToBePresentInElement
查看it('should wait for a series of periodic increments'
示例。要检查元素是否存在,我可以尝试visibilityOf
或presenceOf
。