Protractor: wait method isn't work

心已入冬 提交于 2019-11-30 23:23:57

You need to handle the wait timeout error:

browser.wait(EC.presenceOf(balloon_warning), 3000).then(function () {
    // success handler
}, function (error) {
    expect(true).toBe(false);
});

Finally I found one more solution:

browser.wait(function () {
   return balloon_info.isPresent();
}, 3000).then(function () {
   // success handler
}).thenCatch(function () {
   expect(true).toBe(false);
});

As per your question, what i understand is that you are trying to find if an element is present in the DOM (however, it doesn't necessarily mean that it should be displayed). You are getting a wait error because you are waiting for an element that is not present in the DOM. So it throws an error as you have shown above. To resolve it, try to expect the presence of the element without waiting for it. Because by default protractor has a predefined wait time out for checking for the presence of an element in DOM. Here's a small snippet -

it('Check for presence of the element', function(){
    expect(balloon_warning.isPresent()).toBe(true);
}, 60000); //extra timeout of 60000 so that async error doesn't show up

Now if you want to use wait at any cost then checkout below example -

it('Check for element with wait time of 3000 ms', function(){
    var EC = protractor.ExpectedConditions;
    browser.wait(EC.presenceOf(balloon_warning), 3000).then(function(){
        expect(balloon_warning.isPresent()).toBeTruthy();
    },function(err){
        console.log('error');
    });
}, 60000);

Here if element is not found then wait function will throw error and gets printed in console. Hope it helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!