Things I like about it:
- It uses real browsers to run the tests, quirks and all
- It's got a literate testing interface based on Hamcrest and inspired by LiFT.
public class HomePageTest extends HamcrestWebDriverTestCase {
@Override
protected WebDriver createDriver() {
return new HtmlUnitDriver();
}
public void testHomePageHasTitleAndHeading()
throws Exception {
goTo("http://test.intranet");
assertPresenceOf(title()
.with(text(startsWith("Agile"))));
assertPresenceOf(title()
.with(text(containsString("Cocking and Co."))));
assertPresenceOf(heading(1)
.with(text(equalTo("Agile Application Development"))));
}
}
This won't quite work out of the box, as there is no heading finder, but adding one is easy:
public class HeadingFinder extends HtmlTagFinder {
private final int level;
public HeadingFinder(int level) {
this.level = level;
}
@Override
protected String tagDescription() {
return "heading level "+level;
}
@Override
protected String tagName() {
return "h"+level;
}
public static HeadingFinder heading(int level) {
return new HeadingFinder(level);
}
}
It's fairly new, but there are now pre-built binaries available.
1 comment:
Thanks for showing how easy it is to add a custom finder. Glad you like it. One of the key things we learned from LiFT and Hamcrest was that it's important to allow people to slot in their own concepts so their tests map to their domain, rather than trying to provide a huge generic library. --Robert
Post a Comment