3

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?

Martin Milan
  • 6,346
  • 2
  • 32
  • 44

2 Answers2

3

Try the browser.isElementPresent() instead:

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

If you are curious about the differences, please see:


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();
Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • @MartinMilan okay, updated with one more option, hope this one helps. – alecxe Feb 11 '16 at 16:21
  • 2
    Sadly not - still getting the same problem... I'm really beginning to suspect my environment - I mean this test is hardly rocket science... – Martin Milan Feb 11 '16 at 16:25
  • @MartinMilan same here. Please start with reinstalling protractor from scratch. Are you using jasmine2? Which protractor version? Thanks. – alecxe Feb 11 '16 at 16:26
  • I have to leave the office for a train now, but I will check both of these when I get home. Thanks for your help btw - MASSIVELY appreciated, – Martin Milan Feb 11 '16 at 16:29
  • Protractor looks like version 2.5.1 (taken from npm list) – Martin Milan Feb 12 '16 at 09:15
  • @MartinMilan thank you for the information. And you have `framework: "jasmine2"` configured in the protractor config, right? Could you please also try with the latest protractor 3.1.1? – alecxe Feb 12 '16 at 14:22
  • The protractor framework does indeed say 'jasmine2' - I'll mention about updating protractor, but it's not my call... I am beginning to suspect that the problem is either polling calls from SignalR or the use of $timeout in the AngularJS app. It's all very weird... Must be something we are doing - if protractor was this broken someone would have put "juliemr" against the wall by now lol... – Martin Milan Feb 12 '16 at 14:39
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/103309/discussion-between-alecxe-and-martin-milan). – alecxe Feb 12 '16 at 14:44
  • 1
    @MartinMilan valid point :) Have you tried to play around with `ignoreSynchronization` flag? (I understand that this is an angular app under test, but please try) – alecxe Feb 12 '16 at 19:21
  • I've not used chat... I have used ignoreSynchronization as a temporary means of getting around the problem, but I've been tasked with other tests that have taken priority. THanks for all your help – Martin Milan Feb 15 '16 at 10:51
1

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

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

Community
  • 1
  • 1
KCaradonna
  • 760
  • 6
  • 13