在运行测试之前,AngularJS + Protractor 等待所有 ajax 调用结束/整页加载 [英] AngularJS + Protractor wait for all ajax calls to end / full page load, before running the tests

查看:17
本文介绍了在运行测试之前,AngularJS + Protractor 等待所有 ajax 调用结束/整页加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有更好的方法等到所有页面加载完毕,

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

我的 Angular 页面加载了 Promise,这意味着如果所有 ajaxs 调用还没有结束屏幕上有一个加载器.

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.

我目前正在使用 ptor.sleep(10000),如下例所示:

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

有没有更好的方法?

推荐答案

如果你使用 ng-if 在加载开始/结束时隐藏/显示你的内容,你可以使用以下语法等到页面上出现某个元素(即 ng-if 将阻止该元素在 DOM 中,直到页面完成加载):

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

这篇关于在运行测试之前,AngularJS + Protractor 等待所有 ajax 调用结束/整页加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆