我刚刚开始考虑切换到 Serenity/JS,并想知道拥有基本问题/任务是否是最佳实践?
很多时候我会想检查一个字段是否为空白或有错误,所以我创建了一个“基本问题”来实现这一点:
基本问题
import { Is, See, Target, Task, Wait, Value, Attribute } from 'serenity-js/lib/screenplay-protractor';
import { equals, contains } from '../../../support/chai-wrapper';
import { blank } from '../../../data/blanks';
export class InputFieldQuestion {
constructor(private inputField: Target) { }
isBlank = () => Task.where(`{0} ensures the ${this.inputField} is blank`,
Wait.until(this.inputField, Is.visible()),
See.if(Value.of(this.inputField), equals(blank))
)
hasAnError = () => Task.where(`{0} ensures the ${this.inputField} has an error`,
See.if(Attribute.of(this.inputField).called('class'), contains('ng-invalid'))
)
}
然后我创建特定于场景的类,但只是扩展基本问题:
import { LoginForm } from '../scenery/login_form';
import { InputFieldQuestion } from './common';
class CheckIfTheUsernameFieldQuestion extends InputFieldQuestion {
constructor() { super(LoginForm.Username_Field) }
}
export let CheckIfTheUsernameField = new CheckIfTheUsernameFieldQuestion();
节点导出的美妙之处让我可以导出一个实例化的问题类以在我的规范中使用。
我只是想知道我是否在滥用 Serenity/JS 框架,或者这是否可以?我想建立一个好的框架,并想确保我所做的一切都是为了最佳实践。任何反馈表示赞赏!