Screenplay模式
![]()
Junit的Screenplay
![]()
举例
Actor theReceptionist =newActor().with(WebBrowsing.ability())
theReceptionist.attemptsTo(
Go.to(findOwnersScreen.url()),
Search.forOwnersWith(EMPTY_SEARCH_TERMS),
Count.theNumberOfOwners()
);
assertThat(
theReceptionist.sawThatThe(numberOfOwners()),
was(TheExpectedNumberOfOwners)
);
privatestaticString searchTerms;
@Override
publicvoid performAs(Actor asAReceptionist){
asAReceptionist.attemptTo(
Enter.the(searchTerms).into(findOwnersScreen.searchTerms),
Click.onThe(findOwnersScreen.searchButton)
);
}
publicSearchForOwnersWith(String searchTerms){
this.searchTerms = searchTerms;
}
@Url("owner/find.html")
publicclassFindOwnerScreenextendsWebScreen{
@LocateBy(css="#search-owner-form input")
publicScreenElement searchTerms;
@LocateBy(css="##search-owner-form button")
publicSearchElement searchButton;
publicclassEnterextendsWebDriverInteractionimplementsPerform{
privateString text;
privateScreenElement field;
publicvoid performAs(Actor actor){
web(actor).findElement(field.locator()).sendKeys(text);
}
publicEnter(String text){this.text = text;}
publicstaticEnter the(String text){returnnewEnter(text);}
publicPerforminto(ScreenElement field){
this.field = field;
returnthis;
}
}
优越性
相比于PO模式
- screen的类更小
- 更精简更聚焦的Task类
- 可读性更高
- 继承关系简单
posted on
2018-12-11 14:17
测者陈磊
阅读(
304)
评论()
收藏
举报