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