AngularJS + Protractor wait for all ajax calls to end / full page load, before running the tests

All we need is an easy explanation of the problem, so here it is.

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?

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

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

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply