Search code examples
angularjsasynchronoustimeoutjasmineprotractor

Protractor: wait method isn't work


I try to use wait() method instead sleep(), but it isn't working. I had code:

 browser.actions().click(filter_field).perform();
 browser.sleep(3000);
 if (baloon_info.isPresent()) { //some expections }
 else { expect(true).toBe(false); }

Now I want to do something like:

 var present_pri = browser.wait(function () {
   return balloon_info.isPresent();
 }, 3000);
 if (present_pri) { //some expections }
 else { expect(true).toBe(false); }

But if balloon isn't present I have the error message: Wait timed out after 3117ms instead expected true to be false (present_pri == false)

I tryed to write:

var EC = protractor.ExpectedConditions;
browser.wait(EC.presenceOf(balloon_warning), 3000);
expect(balloon_warning.isPresent()).toBeTruthy();

But I always have the same error. What I doing wrong?


Solution

  • 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);
    });