Пример #1
0
  /**
   * Get differences between doms.
   *
   * @param controlDom The control dom.
   * @param testDom The test dom.
   * @param ignoreAttributes The list of attributes to ignore.
   * @return The differences.
   */
  @SuppressWarnings("unchecked")
  public static List<Difference> getDifferences(
      String controlDom, String testDom, final List<String> ignoreAttributes) {
    try {
      Diff d = new Diff(Helper.getDocument(controlDom), Helper.getDocument(testDom));
      DetailedDiff dd = new DetailedDiff(d);
      dd.overrideDifferenceListener(
          new DifferenceListener() {

            @Override
            public void skippedComparison(Node control, Node test) {}

            @Override
            public int differenceFound(Difference difference) {
              if (difference.getControlNodeDetail() == null
                  || difference.getControlNodeDetail().getNode() == null
                  || difference.getTestNodeDetail() == null
                  || difference.getTestNodeDetail().getNode() == null) {
                return RETURN_ACCEPT_DIFFERENCE;
              }
              if (ignoreAttributes.contains(difference.getTestNodeDetail().getNode().getNodeName())
                  || ignoreAttributes.contains(
                      difference.getControlNodeDetail().getNode().getNodeName())) {
                return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
              }
              return RETURN_ACCEPT_DIFFERENCE;
            }
          });

      return dd.getAllDifferences();
    } catch (Exception e) {
      LOGGER.error("Error with getDifferences: " + e.getMessage(), e);
    }
    return null;
  }
Пример #2
0
  /**
   * Checks whether the folder exists for fname, and creates it if neccessary.
   *
   * @param fname folder name.
   * @throws IOException an IO exception.
   */
  public static void checkFolderForFile(String fname) throws IOException {

    if (fname.lastIndexOf(File.separator) > 0) {
      String folder = fname.substring(0, fname.lastIndexOf(File.separator));
      Helper.directoryCheck(folder);
    }
  }
Пример #3
0
 /**
  * @param element the element.
  * @return a string representation of the element including its attributes.
  */
 public static String getElementString(Element element) {
   if (element == null) {
     return "";
   }
   String text = Helper.removeNewLines(Helper.getTextValue(element)).trim();
   String info = "";
   if (!text.equals("")) {
     info += "\"" + text + "\" ";
     // Helper.removeNewLines(this.text.trim()) + " - ";
   }
   if (element != null) {
     if (element.hasAttribute("id")) {
       info += "ID: " + element.getAttribute("id") + " ";
     }
     info += Helper.getAllElementAttributes(element) + " ";
   }
   return info;
 }
Пример #4
0
  public DomMuteHelper(String outputFolder) {
    String filenameAndPath =
        Helper.addFolderSlashIfNeeded(outputFolder) + "allPossiblePath" + ".txt";
    ArrayList<AllPath> allPath = readAllPossiblePathFile(filenameAndPath);
    for (int i = 0; i < allPath.size(); i++) {
      paths = allPath.get(0);
    }

    domTraceReading = new DomTraceReading(outputFolder);
    Queue<DOMElement> eventSequence = paths.getEventSequence();

    for (DOMElement event : eventSequence) {
      HashMap<String, String> events = event.getElementAttributes();
      Set<String> keys = events.keySet();
      Iterator<String> iter = keys.iterator();
      while (iter.hasNext()) {
        String attrName = iter.next();
        String attrValue = events.get(attrName);
        if (attrName.equals("xpath")) {
          excludedElementsList.add(attrValue);
        }
      }
    }
  }