6

Is there a better way to wait until all page is loaded,

my angular pages are loaded with promise, it means that if all ajaxs call haven't ended yet there is a loader on the screen.

i'm currently using ptor.sleep(10000), like in the following example:

beforeEach(function(){
    ptor = protractor.getInstance();
    driver = ptor.driver;
    ptor.get(base_url);
    ptor.sleep(10000);
});

is there a better way to do it?

Liad Livnat
  • 7,435
  • 16
  • 60
  • 98
  • Found the answer for this in the answer for : http://stackoverflow.com/questions/28808463/what-is-browser-ignoresynchronization-in-protractor – user90766 Jun 22 '16 at 09:19

1 Answers1

6

If you're using ng-if to hide/show your content when loading starts/finishes, you can use the following syntax to wait until a certain element appears on the page (i.e. ng-if will prevent the element from being in the DOM until the page finishes loading):

ptor.findElement(by.id('element-only-shown-after-loading')).then(function (myElement) {
    // Your page should be loaded at this point
});
robert.bo.roth
  • 1,343
  • 3
  • 14
  • 24
  • I don't understand why this works, if the element is not in the DOM shouldn't `findElement` be unable to find it? – Emir Herrera Jun 22 '17 at 00:06
  • 1
    ptor.findElement() waits until it finds that element to resolve it's promise. So you can wait passively until that element appears on the page and then run your code. – robert.bo.roth Jun 28 '17 at 16:24