测者的测试技术笔记: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类

可读性更高

继承关系简单

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 137,128评论 19 139
  • 今夜雷公布雨忙,苍穹闪耀万条光。 轰隆紧凑惊虚梦,疑是南疆炮火扬。 竹影
    竹影_张育清阅读 809评论 4 11
  • 文/长木云伊 风是风打的喷嚏云是云吐的烟圈以词解词的少年兀自孤单 象风一样狂野象云一样自由 顺着溪流向下走却再也找...
    莫嗔堂堂主阅读 251评论 0 0
  • 夜晚,总是我最安静的时候,无论白天怎么闹,怎么作,夜晚,属于安静、惆怅的我。 深夜,看着漆黑的窗外,听着外面若有若...
    雨中的城市阅读 364评论 0 0
  • 活在未来是一件很美好很重要的事情,能帮助我们跳出当下,当下就像一个牢笼,所以我们是被困在当下,就像一个囚徒那样。 ...
    Shirley666阅读 253评论 0 0

友情链接更多精彩内容