首页 > 解决方案 > 在 Serenity 剧本报告中合并“子”可执行文件

问题描述

我创建了一个 LoginToAuth0 任务来自动化和测试我的站点登录到 Auth0 功能。

我的目标是使报告更有意义,并禁止登录凭据。Serenity 有没有办法巩固步骤而不是那么冗长(或者这与 Serenity 本身的想法背道而驰)?

如果提供一个选项来抑制报告所述组中的步骤,那么带有 groupStepName 参数的 should 方法将是完美的。

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()));
    }
  }

}

标签: serenity-bdd

解决方案


You would typically group such tasks in a higher level task. You can also use the IsSilent or CanBeSilent interfaces to make tasks not appear in the reports (useful for tasks used in the givens for example)


推荐阅读