Screenplay模式

 

 

Junit的Screenplay

 

 

举例

  1. Actor theReceptionist =newActor().with(WebBrowsing.ability())
  2. theReceptionist.attemptsTo(
  3. Go.to(findOwnersScreen.url()),
  4. Search.forOwnersWith(EMPTY_SEARCH_TERMS),
  5. Count.theNumberOfOwners()
  6. );
  7. assertThat(
  8. theReceptionist.sawThatThe(numberOfOwners()),
  9. was(TheExpectedNumberOfOwners)
  10. );

 

  • A Task
  1. privatestaticString searchTerms;
  2. @Override
  3. publicvoid performAs(Actor asAReceptionist){
  4. asAReceptionist.attemptTo(
  5. Enter.the(searchTerms).into(findOwnersScreen.searchTerms),
  6. Click.onThe(findOwnersScreen.searchButton)
  7. );
  8. }
  9. publicSearchForOwnersWith(String searchTerms){
  10. this.searchTerms = searchTerms;
  11. }

 

  • A Screen
  1. @Url("owner/find.html")
  2. publicclassFindOwnerScreenextendsWebScreen{
  3. @LocateBy(css="#search-owner-form input")
  4. publicScreenElement searchTerms;
  5. @LocateBy(css="##search-owner-form button")
  6. publicSearchElement searchButton;

 

  • An Action
  1. publicclassEnterextendsWebDriverInteractionimplementsPerform{
  2. privateString text;
  3. privateScreenElement field;
  4. publicvoid performAs(Actor actor){
  5. web(actor).findElement(field.locator()).sendKeys(text);
  6. }
  7. publicEnter(String text){this.text = text;}
  8. publicstaticEnter the(String text){returnnewEnter(text);}
  9. publicPerforminto(ScreenElement field){
  10. this.field = field;
  11. returnthis;
  12. }
  13. }

 

优越性

相比于PO模式
  • screen的类更小
  • 更精简更聚焦的Task类
  • 可读性更高
  • 继承关系简单
posted on 2018-12-11 14:17  测者陈磊  阅读(304)  评论(0)    收藏  举报