Package org.appng.testsupport.validation
Class XPathDifferenceHandler
- java.lang.Object
-
- org.appng.testsupport.validation.DifferenceHandler
-
- org.appng.testsupport.validation.XPathDifferenceHandler
-
- All Implemented Interfaces:
DifferenceListener
public class XPathDifferenceHandler extends DifferenceHandler
ADifferenceListener
which ignores theDifference
if the XPath of the node was added to ignorable expressions usingignoreDifference(String)
. Multiple XPath expressions can be added to the ignore list by callingignoreDifference(String)
. Note that these expressions must be the complete absolute XPath location starting from the document root.- Author:
- Matthias Müller
- See Also:
Difference.getControlNodeDetail()
,Difference.getTestNodeDetail()
,NodeDetail.getXpathLocation()
-
-
Field Summary
-
Fields inherited from interface org.custommonkey.xmlunit.DifferenceListener
RETURN_ACCEPT_DIFFERENCE, RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL, RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR, RETURN_UPGRADE_DIFFERENCE_NODES_DIFFERENT
-
-
Constructor Summary
Constructors Constructor Description XPathDifferenceHandler()
Delegates toXPathDifferenceHandler(boolean)
withstripPositions = true
.XPathDifferenceHandler(boolean stripPositions)
Creates a newXPathDifferenceHandler
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDifferenceListener(String xpath, DifferenceListener differenceListener)
Registers a customDifferenceListener
for the given XPath expressionint
differenceFound(Difference difference)
void
ignoreDifference(String xpath)
Ignore theDifference
with the given XPath expression-
Methods inherited from class org.appng.testsupport.validation.DifferenceHandler
skippedComparison
-
-
-
-
Constructor Detail
-
XPathDifferenceHandler
public XPathDifferenceHandler(boolean stripPositions)
Creates a newXPathDifferenceHandler
.If there is a difference you want to ignore at the following XPath location
/datasource/data/selection[2]/option[4]
you can achieve this by either setting up yourXPathDifferenceHandler
like thisDifferenceHandler differenceHandler = new XPathDifferenceHandler(true); differenceHandler.ignoreDifference("/datasource/data/selection/option");
or thisDifferenceHandler differenceHandler = new XPathDifferenceHandler(false); differenceHandler.ignoreDifference("/datasource/data/selection[2]/option[4]");
In the first case, withstripPositions = true
, you can omit the positions from the expression. As a side effect, everyDifference
with the (stripped) XPath of/datasource/data/selection/option
will be ignored.
In the second case, there needs to be an exact match between the registered XPath location and the one from theDifference
.- Parameters:
stripPositions
- whether or not to strip the positions from the actual XPath of theDifference
before checking the registry for an appropriateDifferenceListener
-
XPathDifferenceHandler
public XPathDifferenceHandler()
Delegates toXPathDifferenceHandler(boolean)
withstripPositions = true
.- See Also:
XPathDifferenceHandler(boolean)
-
-
Method Detail
-
ignoreDifference
public void ignoreDifference(String xpath)
Ignore theDifference
with the given XPath expression- Parameters:
xpath
- the XPath expression. Note that this must be the complete absolute XPath location starting from the document root.
-
addDifferenceListener
public void addDifferenceListener(String xpath, DifferenceListener differenceListener)
Registers a customDifferenceListener
for the given XPath expression- Parameters:
xpath
- the XPath expression. Note that this must be the complete absolute XPath location starting from the document root.differenceListener
- theDifferenceListener
to register
-
differenceFound
public int differenceFound(Difference difference)
- Specified by:
differenceFound
in interfaceDifferenceListener
- Specified by:
differenceFound
in classDifferenceHandler
-
-