在Angular中使用Protractor单击时,Assert按钮被禁用

时间:2015-01-02 10:44:23

标签: javascript angularjs protractor

我们有一个提交按钮,在等待操作完成时被禁用。在这种情况下,操作通过导航到/dashboard页面完成。

我们想在端到端的量角器测试中断言这个'待处理时禁用'行为:

it('should disable button after submission', function(){
  page.usernameTextBox.sendKeys(username);
  page.passwordTextBox.sendKeys('password1');
  page.signInButton.click();
  expect(page.signInButton.getAttribute('disabled')).toContain('true');
  expect(browser.getCurrentUrl()).toContain('/dashboard');
});

disabled属性上的断言失败,因为下一页已加载。这是因为Protractor在运行断言之前等待操作完成 - 即由于竞争条件而没有错过 - Protractor实际上已将其同步,以便在操作完成之前不会运行断言。

如何测试上述行为?

2 个答案:

答案 0 :(得分:1)

现在试试这个: expect(page.signInButton.isEnabled()。toBe(false));

答案 1 :(得分:0)

我知道这个问题几乎与网络开发的石器时代有关,但是自从我在2018年仍然发现它以来,我认为其他人也会这样,而且为了正确的信息,我还是要回答它。< / p>

所以,断言你的按钮有一个名字,你可以用当前版本的量角器做这样的事情:

expect(element(by.name('loginButton')).isEnabled()).toBeFalsy();
相关问题