測定者のテスト技術ノート:Screenplayモード(Journeyモード)

2177 ワード

Screenplayモード(Journeyモード)


Screenplayモード


JunitのScreenplay


例を挙げる

Actor theReceptionist = new Actor().with(WebBrowsing.ability())theReceptionist.attemptsTo(    Go.to(findOwnersScreen.url()),    Search.forOwnersWith(EMPTY_SEARCH_TERMS),    Count.theNumberOfOwners());assertThat(    theReceptionist.sawThatThe(numberOfOwners()),    was(TheExpectedNumberOfOwners));
  • A Task
  •     private static String searchTerms;    @Override    public void performAs(Actor asAReceptionist){        asAReceptionist.attemptTo(                Enter.the(searchTerms).into(findOwnersScreen.searchTerms),                Click.onThe(findOwnersScreen.searchButton)            );        }    public SearchForOwnersWith(String searchTerms){        this.searchTerms = searchTerms;    }
  • A Screen
      @ Url("owner/find.html")  public class FindOwnerScreen extends WebScreen{  @LocateBy(css="#search-owner-form input")  public ScreenElement searchTerms;  @LocateBy(css="##search-owner-form button")  public SearchElement searchButton;
  • An Action
      public class Enter extends WebDriverInteraction implements Perform{      private String text;      private ScreenElement field;      public void performAs(Actor actor){          web(actor).findElement(field.locator()).sendKeys(text);      }      public Enter(String text){this.text = text;}      public static Enter the(String text){return new Enter(text);}      public Perform into(ScreenElement field){          this.field = field;          return this;          }      }

  • 優越性


    POモードよりも
  • screenのクラスはより小さい
  • よりコンパクトでよりフォーカスのTaskクラス
  • 可読性が高い
  • 継承関係単純
  • 転載先:https://juejin.im/post/5c0f3e4e6fb9a049e93c9260