前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >UI自动化的设计模式:Screenplay 模式(Journey 模式)

UI自动化的设计模式:Screenplay 模式(Journey 模式)

作者头像
Criss@陈磊
发布2019-08-02 11:30:11
8530
发布2019-08-02 11:30:11
举报

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类
  • 可读性更高
  • 继承关系简单
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-06-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 质问 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Screenplay模式
  • Junit的Screenplay
  • 举例
    • A Task
      • A Screen
        • An Action
        • 优越性
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档