如何使量角器的零件等待或变为同步? [英] How to make parts of Protractor wait or become synchronous?

查看:127
本文介绍了如何使量角器的零件等待或变为同步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在量角器测试中有这样的代码,它转到主页确定我们需要登录然后调用此函数。注意我在NODE.js环境中运行它:

I have code like this in a protractor test, it goes to a home page determines we need to login and then calls this function. Note I'm running this in a NODE.js environment:

function Login() {
    browser.findElement(by.id('ID')).then(function (ele) {
        ele.sendKeys('SomeUserName');
        browser.findElement(by.id('password')).then(function (ele) {
            ele.sendKeys('SomePassword');
            browser.findElement(by.partialButtonText('Sign in')).then(function (ele) {
                ele.click();
                browser.getCurrentUrl().then(function (url) {
                    expect(url).toBe("http://NextURLAfterClick");
                    debugger;
                });
            });
        });
    });
}

但是在验证<$之前我无法点击这一点击c $ c> browser.getCurrentUrl(),所以发生的事情是我收到登录页面的网址,我想在点击登录后获取网址

But I can't get the click to fire prior to validating the browser.getCurrentUrl(), so what's happening is I'm getting the url of the login page, I want to get the url after the click to login.

我怀疑这是我对这种异步性质的误解。

I suspect it's my misunderstanding of how the Asynchronous nature of this works.

推荐答案


如何使量角器的某些部分等待或变为同步?

How to make parts of Protractor wait or become synchronous?

您可以在 browser.wait()

var urlChanged = function(url) {
  return function () {
    return browser.getCurrentUrl().then(function(actualUrl) {
      return url === actualUrl;
    });
  };
};

element(by.id('ID')).sendKeys('SomeUserName');
element(by.id('password')).sendKeys('SomePassword');
element(by.partialButtonText('Sign in')).click();

browser.wait(urlChanged("http://NextURLAfterClick")), 5000);

其中 urlChanged selenium 条款,是自定义预期条件。

where urlChanged, in selenium terms, is a "Custom Expected Condition".

这篇关于如何使量角器的零件等待或变为同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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