单击按钮后,如何使用量角器测试按钮是否被禁用?

问题描述 投票:0回答:1

单击按钮后,我想检查单击的按钮是否被禁用,但是出现以下错误:

NoSuchElementError: No element found using locator: By(css selector, *[id="saveButton"])

量角器:

const saveButton = await element(by.id('saveButton'));
saveButton.click();
browser.sleep(1000);
await expect(saveButton.isEnabled()).to.be.false;

HTML:

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

角度:

saveArticle() {
    this.isDisable = true;
}

在屏幕上可见的按钮和量角器找到并单击该按钮,但是此后会发生如上的错误。单击后如何检查按钮已禁用?

我想检查单击按钮后禁用了单击的按钮,但是出现以下错误:NoSuchElementError:使用定位器找不到元素:By(css选择器,* [id =“ saveButton”])...] >

angular testing protractor bdd chai
1个回答
0
投票

(saveButton.isEnabled())将返回布尔值。与.toBe(false)进行比较;如果单击按钮后按钮没有立即被禁用,则可以增加睡眠时间。

const saveButton = await element(by.id('saveButton'));
saveButton.click();
browser.sleep(1000);
await expect(saveButton.isEnabled()).toBe(false);
© www.soinside.com 2019 - 2024. All rights reserved.