@Test public void emptyTexts() { Element control = doc.createElement(FOO); Element child = doc.createElement(BAR); control.appendChild(doc.createTextNode("")); control.appendChild(child); child.appendChild(doc.createTextNode(BAR)); Element test = doc.createElement(FOO); Element child2 = doc.createElement(BAR); test.appendChild(child2); child2.appendChild(doc.createTextNode(BAR)); assertFalse(new MultiLevelByNameAndTextSelector(2) .canBeCompared(control, test)); assertTrue(new MultiLevelByNameAndTextSelector(2, true) .canBeCompared(control, test)); }
@Override public boolean canBeCompared(Element controlElement, Element testElement) { Element currentControl = controlElement; Element currentTest = testElement; for (int currentLevel = 0; currentLevel <= levels - 2; currentLevel++) { if (!ElementSelectors.byName.canBeCompared(currentControl, currentTest) || !currentControl.hasChildNodes() || !currentTest.hasChildNodes()) { return false; } Node n1 = getFirstEligibleChild(currentControl); Node n2 = getFirstEligibleChild(currentTest); if (n1.getNodeType() == Node.ELEMENT_NODE && n2.getNodeType() == Node.ELEMENT_NODE) { currentControl = (Element) n1; currentTest = (Element) n2; } else { return false; } } return ElementSelectors.byNameAndText.canBeCompared(currentControl, currentTest); }
MultiLevelByNameAndTextSelector implements ElementSelector { @Override public boolean canBeCompared(Element controlElement, Element testElement) { Element currentControl = controlElement; Element currentTest = testElement; for (int currentLevel = 0; currentLevel <= levels - 2; currentLevel++) { if (!ElementSelectors.byName.canBeCompared(currentControl, currentTest) || !currentControl.hasChildNodes() || !currentTest.hasChildNodes()) { return false; } Node n1 = getFirstEligibleChild(currentControl); Node n2 = getFirstEligibleChild(currentTest); if (n1.getNodeType() == Node.ELEMENT_NODE && n2.getNodeType() == Node.ELEMENT_NODE) { currentControl = (Element) n1; currentTest = (Element) n2; } else { return false; } } return ElementSelectors.byNameAndText.canBeCompared(currentControl, currentTest); } }
MultiLevelByNameAndTextSelector implements ElementSelector { @Override public boolean canBeCompared(Element controlElement, Element testElement) { Element currentControl = controlElement; Element currentTest = testElement; for (int currentLevel = 0; currentLevel <= levels - 2; currentLevel++) { if (!ElementSelectors.byName.canBeCompared(currentControl, currentTest) || !currentControl.hasChildNodes() || !currentTest.hasChildNodes()) { return false; } Node n1 = getFirstEligibleChild(currentControl); Node n2 = getFirstEligibleChild(currentTest); if (n1.getNodeType() == Node.ELEMENT_NODE && n2.getNodeType() == Node.ELEMENT_NODE) { currentControl = (Element) n1; currentTest = (Element) n2; } else { return false; } } return ElementSelectors.byNameAndText.canBeCompared(currentControl, currentTest); } MultiLevelByNameAndTextSelector(int levels);  MultiLevelByNameAndTextSelector(int levels, boolean ignoreEmptyTexts); }
MultiLevelByNameAndTextSelector implements ElementSelector { @Override public boolean canBeCompared(Element controlElement, Element testElement) { Element currentControl = controlElement; Element currentTest = testElement; for (int currentLevel = 0; currentLevel <= levels - 2; currentLevel++) { if (!ElementSelectors.byName.canBeCompared(currentControl, currentTest) || !currentControl.hasChildNodes() || !currentTest.hasChildNodes()) { return false; } Node n1 = getFirstEligibleChild(currentControl); Node n2 = getFirstEligibleChild(currentTest); if (n1.getNodeType() == Node.ELEMENT_NODE && n2.getNodeType() == Node.ELEMENT_NODE) { currentControl = (Element) n1; currentTest = (Element) n2; } else { return false; } } return ElementSelectors.byNameAndText.canBeCompared(currentControl, currentTest); } MultiLevelByNameAndTextSelector(int levels);  MultiLevelByNameAndTextSelector(int levels, boolean ignoreEmptyTexts); @Override boolean canBeCompared(Element controlElement,
                                 Element testElement); }
MultiLevelByNameAndTextSelector implements ElementSelector { @Override public boolean canBeCompared(Element controlElement, Element testElement) { Element currentControl = controlElement; Element currentTest = testElement; for (int currentLevel = 0; currentLevel <= levels - 2; currentLevel++) { if (!ElementSelectors.byName.canBeCompared(currentControl, currentTest) || !currentControl.hasChildNodes() || !currentTest.hasChildNodes()) { return false; } Node n1 = getFirstEligibleChild(currentControl); Node n2 = getFirstEligibleChild(currentTest); if (n1.getNodeType() == Node.ELEMENT_NODE && n2.getNodeType() == Node.ELEMENT_NODE) { currentControl = (Element) n1; currentTest = (Element) n2; } else { return false; } } return ElementSelectors.byNameAndText.canBeCompared(currentControl, currentTest); } MultiLevelByNameAndTextSelector(int levels);  MultiLevelByNameAndTextSelector(int levels, boolean ignoreEmptyTexts); @Override boolean canBeCompared(Element controlElement,
                                 Element testElement);  }