【问题标题】:How can I check the button which clicked is disabled with using protractor?如何使用量角器检查单击的按钮是否被禁用?
【发布时间】:2020-06-17 10:57:23
【问题描述】:

我想在按钮点击后检查按钮是否被禁用,但禁用属性是动态的,我无法获取属性的最后状态:

量角器:

const saveButton = element(by.id('saveButton'));

saveButton.click();
browser.sleep(1000);
await saveButton.isEnabled().then(enabled => {
    expect(enabled).to.be.false;
});

HTML:

<button id="saveButton" [disabled]="isDisabled" mat-button (click)="saveArticle()">
    Save
</button>

角度:

this.isDisabled = false;

saveArticle() {
    this.isDisabled = true;

    this.http.get('http://url').subscribe((response) => {
        this.isDisabled = false;
    });
}

Disabled 属性像上面一样动态变化,这不能正常工作。 isEnabled() 方法总是返回 true。点击后如何验证按钮是否被禁用?

【问题讨论】:

  • 点击前后按钮属性有区别吗?如果是这样,您只需检查属性值以确保该按钮被禁用。

标签: angular testing protractor bdd chai


【解决方案1】:

你在使用 Jasmine 匹配器吗?如果是这样,这就足够了:

const saveButton = element(by.id('saveButton'));

await saveButton.click();
browser.sleep(1000);
expect(await saveButton.isEnabled()).toBe(false);

【讨论】:

    【解决方案2】:

    您可以尝试使用 getAttribute('') 并断言返回值。请注意,getAttribute 可能返回 null(如果属性没有值)或字符串

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-18
      • 1970-01-01
      • 2011-05-11
      • 2011-02-16
      • 2011-09-20
      • 2014-05-19
      • 1970-01-01
      相关资源
      最近更新 更多