我已经创建了LoginToAuth0任务,以自动化和测试我的网站登录到Auth0功能。
我的目标是使报告更有意义,并取消登录凭据。 Serenity中是否有一种方法可以巩固步骤,而不是那么冗长(或者这与Serenity本身的想法背道而驰)?
带有groupStepName参数的应当方法应该是完美的,如果它提供了一个选项,可以禁止报告所述组中的步骤。
public final void should(String groupStepName, Consequence... consequences) {...}
这可能吗?还可以对atteptsTo做同样的事情吗?
先谢谢您,
蒂姆
public class LoginToAuth0 implements Task {
@Managed()
public WebDriver webDriver;
Actor actor;
public Auth0Site auth0Site;
private String email;
private String password;
protected LoginToAuth0(String email, String password) {
this.email = email;
this.password = password;
}
@Override
public <T extends Actor> void performAs(T actor) {
givenThat(actor).should(eventually(seeThat(auth0Site.isPage())),
eventually(seeThat(the(Auth0Site.loginContainer()), isCurrentlyVisible())),
eventually(seeThat(the(Auth0Site.emailField()), isCurrentlyVisible())),
seeThat(the(Auth0Site.passwordField()), isCurrentlyVisible()),
seeThat(the(Auth0Site.submitButton()), isCurrentlyVisible()));
when(actor).attemptsTo(Enter.theValue(email).into(Auth0Site.emailField()), new EnterPassword(),
Click.on(Auth0Site.submitButton()));
then(actor).should(eventually(seeThat(auth0Site.isPage(), not(true))));
}
public static class Builder {
private String email = null;
private String password = null;
public Builder withCredentials(String email, String password) {
this.email = email;
this.password = password;
return this;
}
public LoginToAuth0 build() {
if (this.email == null || this.password == null)
throw new IllegalStateException();
return Tasks.instrumented(LoginToAuth0.class, email, password);
}
}
private class EnterPassword extends SilentPerformable {
@Override
public <T extends Actor> void performAs(T actor) {
actor.attemptsTo(Enter.theValue(password).into(Auth0Site.passwordField()));
}
}
}
答案 0 :(得分:0)
您通常会将此类任务归为更高级别的任务。您还可以使用IsSilent或CanBeSilent界面使任务不出现在报告中(例如,用于给定中使用的任务)