量角器不等待 angular2 加载 [英] Protractor not waiting for angular2 to load

查看:50
本文介绍了量角器不等待 angular2 加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

量角器版本:5.1.2
节点版本:6.9.0
角度版本:2.4.10

Protractor version: 5.1.2
Node version: 6.9.0
Angular version: 2.4.10

OnPrepare 函数我正在执行 browser.get('/').在此之后,我将在 it 中进行登录.
第一个问题是它抛出错误,因为未调用异步函数.在做了一次失败的研究后,我添加了 browser.sleep(500) 然后上面的代码停止了,并执行了登录 it 案例.

OnPrepare function i am doing browser.get('/'). After this i am doing a login in a it.
First issue is it throws error as async function was not called. After doing a failed research i added browser.sleep(500) then the above stopped to come and executed the login it case.

在那之后,我必须点击登陆页面上的一个按钮,然后导航到另一个页面并点击另一个按钮.这里也没有说找不到定位器的元素.但是如果我添加 browser.waitForAngular()browser.sleep(),然后它开始工作.我不能每次都明确添加这个.此外,当我使用量角器(版本:1.3)时,它从未发生过.

After that i have to click a button on landing page and then navigate to another page and click another button.Here also it fails saying that no element found for the locator.But if i add browser.waitForAngular() or browser.sleep(), then it starts to work.I can not add this explicitly everytime. Moreover when i worked with protractor(version: 1.3), it never used to happen.

所以我认为量角器的问题不是等待角度同步.
任何解决方案表示赞赏.

So the problem I think is protractor is not waiting for the angular to synchronize.
Any solution is appreciated.

量角器配置文件

exports.config = {
directConnect: true,
useAllAngular2AppRoots: true,
specs: ['./**/*.spec.js'],
baseUrl: 'http://10.209.1.38:9090',
framework: 'jasmine2',
capabilites: {
    'browserName': 'chrome'
},
jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 60000
},
onPrepare: function () {
    browser.driver.manage().window().maximize();
    browser.get('/');
    browser.sleep(500);
 }
};

推荐答案

Protractor 在执行测试之前不一定要等待 onPrepare 完全完成.

Protractor doesn't necessarily wait for onPrepare to be completely finished, before executing the test.

但是,您可以选择在 onPrepare 中返回一个 promise,然后量角器将在继续执行之前等待.

However, you can optionally return a promise within onPrepare, which then Protractor will await before continuing execution.

在此处查看此问题的详细信息对应此处为量角器文档.

就我而言,我将登录步骤(填写用户名和密码,单击登录)添加到 onPrepare 函数,该函数也创建了承诺,因此触发量角器测试执行以等待 onPrepare-Promises 得到解决.

For my case I added the Login-Steps (fill username and password, click Login) to the onPrepare-function, which also creates promises and therefore triggers Protractor test execution to wait until onPrepare-Promises are resolved.

onPrepare: function () {
    var login_page = require('../page/login_page.js');
    browser.driver.manage().window().maximize();
    browser.get('/');
    login_page.enterUserName('user');
    login_page.enterPassword('password');
    login_page.clickLogin();
}

这篇关于量角器不等待 angular2 加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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