Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor hanging on IsPresent() -- Or any other Action

I am working on trying to get some end to end tests implemented for an AngularJS site, and I am having a bit of an issue getting past a call to the IsPresent() method on the ElementFinder returned by a call to the element method.

Sadly I am governed by rules from my employer preventing me from posting ANY of our code on StackOverflow, but essentially this is what I am doing...

describe('Some feature', function () {
    it('Some Scenario', function () {

        browser.get(browser.baseUrl + '/#/somePage');

        var ee = element(by.css('.test-comment'));
        expect(ee.isPresent()).toBeTruthy();

    });
});

If I comment out the call to the expect() method, then the test executes and passes without issue. If I leave it in, I get :

Failed: Timed out waiting for Protractor to synchronize with the page after 20 seconds. Please see https://github.com/angular/protractor/blob/master/docs/fa q.md. The following tasks were pending: - $timeout: function (){n=null}

This doesn't make any sense to me - the IsPresent() method returns a promise, which is resolved by the expect method, or at least that is what I would expect to happen.

Any clues?

like image 243
Martin Milan Avatar asked Nov 15 '25 19:11

Martin Milan


2 Answers

Try the browser.isElementPresent() instead:

expect(browser.isElementPresent(ee)).toBeTruthy();

If you are curious about the differences, please see:

  • In protractor, browser.isElementPresent vs element.isPresent vs element.isElementPresent

Also, you may introduce the "presence of" explicit wait before making the expectation:

var EC = protractor.ExpectedConditions;
var ee = element(by.css('.test-comment'));

browser.wait(EC.presenceOf(ee), 5000);
expect(ee.isPresent()).toBeTruthy();
like image 101
alecxe Avatar answered Nov 18 '25 18:11

alecxe


.isDisplayed() might be of help to you as well.

See What is the difference between the isPresent and isDisplayed methods for more info.

like image 23
KCaradonna Avatar answered Nov 18 '25 20:11

KCaradonna



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!