Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 733
Liad Livnat Avatar asked Apr 02 '14 09:04

Liad Livnat


1 Answers

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
});
like image 187
robert.bo.roth Avatar answered Oct 02 '22 02:10

robert.bo.roth