测者的测试技术笔记:Screenplay 模式(Journey 模式)


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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值