Hi, I like the idea !
I think we can go even further by using http://jsoup.org/ for most of TagTester's internal work. But this will need more thinking. TagTester is part of wicket-core and we will have to make jsoup an optional dependency. Maybe for Wicket 8.x ... Or create a new project at WicketStuff, make it functional and later merge it to Wicket if all goes well. Martin Grigorov Wicket Training and Consulting https://twitter.com/mtgrigorov On Tue, Nov 25, 2014 at 10:56 PM, Kees van Dieren <[email protected]> wrote: > Hi developers, > > Currently we are doing a project that has most of its formatting based on > absence or presence on CSS class names. Some of testing is done using > TagTester. > > We would like to have some features on TagTester to make unit-testing and > asserting things easier. > > Basically those methods would be useful: > > In WicketTester / BaseWicketTester class: > > /** > * Gives all tags that have the given css className. This includes tags > that have other classNames as well, e.g. > * <pre> > * <span class="foo bar">hi</span> > * </pre> > * will be returned for: > * > * <pre> > * tester.getTagsByClassName("foo"); > * </pre> > * @return > * > */ > public List<TagTester> getTagsByClassName(String className); > > public TagTester getTagByClassName(String className); > > In TagTester class: > /** > * <p>Asserts that given <code>className</code> is set for this tag.</p> > * > * > * <p>This tag might also have other class names. Given this tag:</p> > * <pre> > * <span class="foo bar">hi</span> > * </pre> > * this assertion will pass: > * <pre> > * tester.assertHasClassName("foo"); > * </pre> > * > */ > public TagTester assertHasClass(String className) { > // TODO: implement this > return this; > } > > public TagTester assertHasAttribute(String attribute) { > // TODO: implement this > return this; > } > > public TagTester assertAttributeContains(String attribute, String > partialValue) { > // TODO: implement this > return this; > } > > public TagTester assertAttributeIs(String attribute, String value) { > // TODO: implement this > return this; > } > > These changes would have the following advantages for us: > * Wicket tests for our pages and panels gets more compact and more > readable. > * Assertion failure messages can be much more informative. > > Example of current assertion: > assertTrue(tagTester.attributeContains("class", "menuitem-active")) > (Assertion message not specific / informative) > > New assertion: > tagTester.assertHasClass("menuitem-active"); > Sample assertion failed message: <li class="menuitem"><a > href="/">home</a></li> expected to have style class 'menuitem-active'" > > Does this make sense? > > If wicket developers like the idea, I am willing to contribute those > features to Wicket. > > Best regards, > > Kees van Dieren >
