在运行测试之前,AngularJS + Protractor等待所有ajax调用结束/整页加载 [英] 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,
我的棱角分页上都充满了诺言,这意味着如果所有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屋!