public class TagTester extends Object
It also gives a more programmatic way of testing the generated output, by not having to worry about precisely how the markup looks instead of which attributes exists on the given tags, and what values they have.
Example:
...
TagTester tagTester = application.getTagByWicketId("form");
assertTrue(tag.hasAttribute("action"));
...
| Modifier and Type | Method and Description |
|---|---|
static TagTester |
createTagByAttribute(String markup,
String tagName)
Deprecated.
use
createTagByName(String, String) instead |
static TagTester |
createTagByAttribute(String markup,
String attribute,
String value)
Static factory method for creating a
TagTester based on a tag found by an
attribute with a specific value. |
static TagTester |
createTagByName(String markup,
String tagName)
Static factory method for creating a
TagTester based on a tag name. |
static TagTester |
createTagsByAttribute(String markup,
String attribute,
String value)
Deprecated.
|
static List<TagTester> |
createTagsByAttribute(String markup,
String attribute,
String value,
boolean stopAfterFirst)
Static factory method for creating a
TagTester based on a tag found by an
attribute with a specific value. |
String |
getAttribute(String attribute)
Gets the value for a given attribute.
|
boolean |
getAttributeContains(String attribute,
String partialValue)
Checks if an attribute contains the specified partial value.
|
boolean |
getAttributeEndsWith(String attribute,
String expected)
Checks if an attribute's value ends with the given parameter.
|
boolean |
getAttributeIs(String attribute,
String expected)
Checks if an attribute's value is the exact same as the given value.
|
TagTester |
getChild(String tagName)
Checks if the tag has a child with the given
tagName. |
TagTester |
getChild(String attribute,
String value)
Gets a child tag for testing.
|
String |
getMarkup()
Gets the markup for this tag.
|
String |
getName()
Gets the tag's name.
|
String |
getValue()
Returns the value for this tag.
|
boolean |
hasAttribute(String attribute)
Tests if the tag contains the given attribute.
|
boolean |
hasChildTag(String tagName)
Checks if the tag has a child with the given
tagName. |
public String getName()
public boolean hasAttribute(String attribute)
attribute - an attribute to look for in the tagtrue if the tag has the attribute, false if not.public String getAttribute(String attribute)
attribute - an attribute to look for in the tagnull if it isn't found.public boolean getAttributeContains(String attribute, String partialValue)
For example:
Markup:
<span wicket:id="helloComp" class="style1 style2">Hello</span>
Test:
TagTester tester = application.getTagByWicketId("helloComp");
assertTrue(tester.getAttributeContains("class", "style2"));
attribute - the attribute to test onpartialValue - the partial value to test if the attribute value contains ittrue if the attribute value contains the partial valuepublic boolean getAttributeIs(String attribute, String expected)
attribute - an attribute to testexpected - the value which should be the same at the attribute's valuetrue if the attribute's value is the same as the given valuepublic boolean getAttributeEndsWith(String attribute, String expected)
attribute - an attribute to testexpected - the expected valuetrue if the attribute's value ends with the expected valuepublic boolean hasChildTag(String tagName)
tagName.tagName - the tag name to search fortrue if this tag has a child with the given tagName.public TagTester getChild(String tagName)
tagName.tagName - the tag name to search fortrue if this tag has a child with the given tagName.public TagTester getChild(String attribute, String value)
TagTester instance.attribute - an attribute on the child tag to search forvalue - a value that the attribute must haveTagTester for the child tagpublic String getMarkup()
public String getValue()
public static TagTester createTagByName(String markup, String tagName)
TagTester based on a tag name. Please note
that it will return the first tag which matches the criteria.markup - the markup to look for the tag to create the TagTester from the value
which the attribute must haveTagTester which matches the tag by name in the markup@Deprecated public static TagTester createTagByAttribute(String markup, String tagName)
createTagByName(String, String) insteadTagTester based on a tag name. Please note
that it will return the first tag which matches the criteria.markup - the markup to look for the tag to create the TagTester from
the value which the attribute must haveTagTester which matches the tag by name in the markuppublic static TagTester createTagByAttribute(String markup, String attribute, String value)
TagTester based on a tag found by an
attribute with a specific value. Please note that it will return the first tag which matches
the criteria. It's therefore good for attributes such as "id" or "wicket:id", but only if
"wicket:id" is unique in the specified markup.markup - the markup to look for the tag to create the TagTester fromattribute - the attribute which should be on the tag in the markupvalue - the value which the attribute must haveTagTester which matches the tag in the markup, that has the given
value on the given attribute@Deprecated public static TagTester createTagsByAttribute(String markup, String attribute, String value)
TagTester based on a tag found by an
attribute with a specific value. Please note that it will return the first tag which matches
the criteria. It's therefore good for attributes such as "id" or "wicket:id", but only if
"wicket:id" is unique in the specified markup.markup - the markup to look for the tag to create the TagTester fromattribute - the attribute which should be on the tag in the markupvalue - the value which the attribute must haveTagTester which matches the tag in the markup, that has the given
value on the given attributepublic static List<TagTester> createTagsByAttribute(String markup, String attribute, String value, boolean stopAfterFirst)
TagTester based on a tag found by an
attribute with a specific value. Please note that it will return the first tag which matches
the criteria. It's therefore good for attributes suck as "id" or "wicket:id", but only if
"wicket:id" is unique in the specified markup.markup - the markup to look for the tag to create the TagTester fromattribute - the attribute which should be on the tag in the markupvalue - the value which the attribute must havestopAfterFirst - if true search will stop after the first matchTagTester which matches the tag in the markup, that has the given
value on the given attributeCopyright © 2006–2021 Apache Software Foundation. All rights reserved.