Exemplo n.º 1
0
  private boolean xpathInput(EmbeddedBrowser browser, String path, String value) {
    log.info("xpathInput(EmbeddedBrowser browser, String path, String value)");
    assert (browser != null);
    Document doc = null;

    try {
      doc = DomUtils.asDocument(browser.getStrippedDom());
    } catch (IOException e) {
      log.debug(e.getMessage());
      return false;
    }

    assert (doc != null);
    if (xpathQuery(doc, path)) {
      Identification id = new Identification();
      id.setHow(How.xpath);
      id.setValue(path);
      try {
        log.info("Browser input\n");
        log.info(How.xpath.toString());
        log.info(path);
        return browser.input(id, value);
      } catch (CrawljaxException e) {
        log.info(e.getMessage());
        return false;
      }
    }

    return false;
  }
  /**
   * initialize the current used controller. 1. build the index state, 2. create a new CrawlSession
   * from the new index state and the golden standard, 3. run revisitedStatesPlugins on the new
   * found index.
   *
   * @param golderStandard the SFG containing all the original states & edges.
   * @param goldenIndexState the golden/original index state.
   */
  private void initializeController(StateFlowGraph golderStandard, StateVertix goldenIndexState) {
    EmbeddedBrowser browser = null;
    try {
      browser = getBrowserPool().requestBrowser();
    } catch (InterruptedException e) {
      LOGGER.error("The request for a browser was interuped", e);
    }

    browser.goToUrl(this.getConfigurationReader().getCrawlSpecificationReader().getSiteUrl());
    doBrowserWait(browser);

    /** Build the index state */
    StateVertix indexState =
        new StateVertix(
            browser.getCurrentUrl(), "index", browser.getDom(), getStrippedDom(browser));

    /** Build the CrawlSession */
    CrawlSession session =
        new CrawlSession(
            getBrowserPool(),
            golderStandard,
            indexState,
            getStartCrawl(),
            getConfigurationReader());
    setSession(session);

    // Because of new Index must be checked run the onRevisitedStatesPlugins
    CrawljaxPluginsUtil.runOnRevisitStatePlugins(session, goldenIndexState);

    // Release the browser
    this.getBrowserPool().freeBrowser(browser);
  }
Exemplo n.º 3
0
  private boolean xpathInput(
      EmbeddedBrowser browser, StateVertex vertex, String path, String value) {
    log.debug("xpathInput(EmbeddedBrowser browser, StateVertex vertex, String path, String value)");
    Document doc = null;
    try {
      doc = vertex.getDocument();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    assert (doc != null);
    if (xpathQuery(doc, path)) {
      Identification id = new Identification();
      id.setHow(How.xpath);
      id.setValue(path);
      try {
        return browser.input(id, value);
      } catch (CrawljaxException e) {
        log.debug(e.getMessage());
        return false;
      }
    }

    return false;
  }
Exemplo n.º 4
0
  public boolean executeInput(EmbeddedBrowser browser, BioFuzzFieldInput in) {
    log.info("executeInput(EmbeddedBrowser browser,Input in)");
    assert (browser != null);
    assert (in != null);

    switch (in.getAction()) {
      case TEXT_INPUT:
        log.info("text input");
        boolean ret = true;
        for (String elementId : in.getElementIds()) {
          log.debug("execute input for" + elementId);
          ret = ret && xpathInput(browser, elementId, in.getInputValue());
        }
        return ret;
      case CLICK:
        log.debug("click");
        assert (in.getElementIds().size() > 0);
        return xpathEvent(browser, in.getElementId(0), EventType.click);
      case GO_TO_URL:
        log.debug("go to url");
        try {
          browser.goToUrl(new URL(in.getInputValue()));
          return true;
        } catch (MalformedURLException e) {
          // TODO Auto-generated catch block
          return false;
        }
      default:
        break;
    }

    return false;
  }
Exemplo n.º 5
0
  public boolean executeInput(EmbeddedBrowser browser, StateVertex vertex, BioFuzzFieldInput in) {
    log.debug("executeInput(EmbeddedBrowser browser,StateVertex vertex,Input in) ");
    log.debug("Input: " + in.toString());
    assert (browser != null);
    assert (vertex != null);
    assert (in != null);
    switch (in.getAction()) {
      case TEXT_INPUT:
        boolean ret = true;
        for (String elementId : in.getElementIds()) {
          ret = ret & xpathInput(browser, vertex, elementId, in.getInputValue());
        }
        return ret;
      case CLICK:
        return xpathEvent(browser, vertex, in.getElementId(0), EventType.click);
      case GO_TO_URL:
        try {
          browser.goToUrl(new URL(in.getInputValue()));
          return true;
        } catch (MalformedURLException e) {
          // TODO Auto-generated catch block
          return false;
        }
    }

    return false;
  }
Exemplo n.º 6
0
  // Based on the fireEvent Method in the crawljax core
  private boolean fireEvent(Eventable eventable, EmbeddedBrowser browser) {
    log.debug("fireEvent(Eventable eventable, EmbeddedBrowser browser)");
    Eventable eventToFire = eventable;

    boolean isFired = false;
    try {
      isFired = browser.fireEventAndWait(eventToFire);
      // } catch (ElementNotVisibleException | NoSuchElementException e) {
      //       return false;
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      return false;
    }

    if (isFired) {
      return true;
    } else {
      return false; // no event fired
    }
  }
Exemplo n.º 7
0
  public boolean xpathEvent(EmbeddedBrowser browser, String path, EventType t) {
    log.debug("xpathEvent without start\n");
    Document doc = null;
    assert (browser != null);
    try {
      doc = DomUtils.asDocument(browser.getStrippedDom());
    } catch (IOException e) {
      log.debug(e.getMessage());
      return false;
    }

    assert (doc != null);
    if (xpathQuery(doc, path)) {
      Identification id = new Identification();
      id.setHow(How.xpath);
      id.setValue(path);
      Eventable ev = new Eventable();
      ev.setEventType(t);
      ev.setIdentification(id);

      return fireEvent(ev, browser);
    }
    return false;
  }
 @Override
 public boolean check(EmbeddedBrowser browser) {
   return browser.getCurrentUrl().toLowerCase().contains(url);
 }
 @Override
 public boolean isSatisfied(EmbeddedBrowser browser) {
   return browser.elementExists(identification);
 }