public class XPathDifferenceHandler extends DifferenceHandler
DifferenceListener
which ignores the Difference
if the XPath of the node was added to ignorable
expressions using ignoreDifference(String)
. Multiple XPath expressions can be added to the ignore list by
calling ignoreDifference(String)
. Note that these expressions must be the complete absolute XPath location
starting from the document root.Difference.getControlNodeDetail()
,
Difference.getTestNodeDetail()
,
NodeDetail.getXpathLocation()
RETURN_ACCEPT_DIFFERENCE, RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL, RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR, RETURN_UPGRADE_DIFFERENCE_NODES_DIFFERENT
Constructor and Description |
---|
XPathDifferenceHandler()
Delegates to
XPathDifferenceHandler(boolean) with stripPositions = true . |
XPathDifferenceHandler(boolean stripPositions)
Creates a new
XPathDifferenceHandler . |
Modifier and Type | Method and Description |
---|---|
void |
addDifferenceListener(String xpath,
DifferenceListener differenceListener)
Registers a custom
DifferenceListener for the given XPath expression |
int |
differenceFound(Difference difference) |
void |
ignoreDifference(String xpath)
Ignore the
Difference with the given XPath expression |
skippedComparison
public XPathDifferenceHandler(boolean stripPositions)
XPathDifferenceHandler
.
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 your
XPathDifferenceHandler
like this
DifferenceHandler differenceHandler = new XPathDifferenceHandler(true); differenceHandler.ignoreDifference("/datasource/data/selection/option");or this
DifferenceHandler differenceHandler = new XPathDifferenceHandler(false); differenceHandler.ignoreDifference("/datasource/data/selection[2]/option[4]");In the first case, with
stripPositions = true
, you can omit the positions from the expression. As a side
effect, every Difference
with the (stripped) XPath of /datasource/data/selection/option
will be
ignored.Difference
.
stripPositions
- whether or not to strip the positions from the actual XPath of the Difference
before checking
the registry for an appropriate DifferenceListener
public XPathDifferenceHandler()
XPathDifferenceHandler(boolean)
with stripPositions = true
.XPathDifferenceHandler(boolean)
public void ignoreDifference(String xpath)
Difference
with the given XPath expressionxpath
- the XPath expression. Note that this must be the complete absolute XPath location starting from the
document root.public void addDifferenceListener(String xpath, DifferenceListener differenceListener)
DifferenceListener
for the given XPath expressionxpath
- the XPath expression. Note that this must be the complete absolute XPath location starting from the
document root.differenceListener
- the DifferenceListener
to registerpublic int differenceFound(Difference difference)
differenceFound
in interface DifferenceListener
differenceFound
in class DifferenceHandler
Copyright © 2011–2019 aiticon GmbH. All rights reserved.