webUI自动化测试另一个设计模式:Screenplay 模式(Journey 模式)
- 2019 年 12 月 12 日
- 筆記
来源:测者陈磊V社 北京社
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; publicvoid 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://blog.csdn.net/crisschan
星云测试
http://www.teststars.cc
奇林软件
http://www.kylinpet.com
联合通测
http://www.quicktesting.net