如何使用量角器使用 formGroup 或 ngif 元素测试登录应用程序的验证消息?

How to test a login application for validation messages using formGroup or ngif element using protractor?

我想测试我的登录应用程序是否正确显示验证消息。在不为表单添加 id 的情况下,我可以使用 ngclass 检查吗?

<form [formGroup]="authForm">
        <div class="form-group">
            <label for="email">Email address</label>
            <div class="invalid-feedback" *ngIf="authForm.get('email').hasError('required')">
                Email is required.
            </div>
        </div>
    </form>

您可以使用以下代码进行验证。如果警报显示在 运行 时间内。在字段内部单击,然后单击另一个字段而不发送任何值。

validationMessage = element(by.css('div.form-group>div');

validationMessage.getText().then((value:string) =>{
expect(value).toBe('Email is required.');
}

有关信息,请参阅 https://www.protractortest.org/#/locators

希望对你有帮助