AngularJS + Protractor wait for all ajax calls to

2019-03-14 00:46发布

问题:

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?

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