Package com.crawljax.core.state

Examples of com.crawljax.core.state.StateVertex


    polledActions = new AtomicInteger();
    Mockito.doAnswer(new Answer<Void>() {

      @Override
      public Void answer(InvocationOnMock invocation) throws Throwable {
        StateVertex task = (StateVertex) invocation.getArguments()[0];
        CandidateCrawlAction action = candidateActions.pollActionOrNull(task);
        while (action != null) {
          // Slight delay to simulate the threading better
          Thread.sleep(25);
          polledActions.incrementAndGet();
View Full Code Here


    assertThat(counterFor(OnUrlLoadPlugin.class), is(1));
  }

  @Test
  public void revisitStatePluginIsCalled() throws Exception {
    StateVertex currentState = mock(StateVertex.class);
    plugins.runOnRevisitStatePlugins(context, currentState);
    verify(onRevisitStatePlugin).onRevisitState(context, currentState);
    assertThat(counterFor(OnRevisitStatePlugin.class), is(1));
  }
View Full Code Here

    assertThat(counterFor(OnInvariantViolationPlugin.class), is(1));
  }

  @Test
  public void domChangeNotifierIsCalled() {
    StateVertex stateBefore = mock(StateVertex.class);
    Eventable eventable = mock(Eventable.class);
    StateVertex stateAfter = mock(StateVertex.class);
    String oldDom = "old";
    String newDom = "new";
    when(stateBefore.getDom()).thenReturn(oldDom);
    when(stateAfter.getDom()).thenReturn(newDom);

    plugins.runDomChangeNotifierPlugins(context, stateBefore, eventable, stateAfter);
    verify(domChange).isDomChanged(context, oldDom, eventable, newDom);

    assertThat(counterFor(DomChangeNotifierPlugin.class), is(1));
View Full Code Here

    assertThat(counterFor(OnFireEventFailedPlugin.class), is(1));
  }

  @Test
  public void whenDomChangeErrorsTheDefaultIsUsed() {
    StateVertex stateBefore = mock(StateVertex.class);
    Eventable eventable = mock(Eventable.class);
    StateVertex stateAfter = mock(StateVertex.class);
    String oldDom = "old";
    String newDom = "new";
    when(stateBefore.getDom()).thenReturn(oldDom);
    when(stateAfter.getDom()).thenReturn(newDom);
    when(domChange.isDomChanged(context, oldDom, eventable, newDom)).thenThrow(
            new RuntimeException("This is an expected excpetion. ignore"));
    assertThat(
            plugins.runDomChangeNotifierPlugins(context, stateBefore, eventable, stateAfter),
            is(true));
View Full Code Here

   *             when the method is invoked more than once.
   */
  public void setup(StateVertex indexState) {
    if (!isSet.getAndSet(true)) {
      LOG.debug("Setting up the crawlsession");
      StateVertex added = stateFlowGraph.putIndex(indexState);
      Preconditions.checkArgument(added == null, "Could not set the initial state");
      session = new CrawlSession(config, stateFlowGraph, indexState, registry);
    } else {
      throw new IllegalStateException("Session is already set");
    }
View Full Code Here

    return graph.getShortestPath(graph.getInitialState(), crawlTask);
  }

  private void follow(CrawlPath path, StateVertex targetState)
          throws StateUnreachableException, CrawljaxException {
    StateVertex curState = context.getSession().getInitialState();

    for (Eventable clickable : path) {
      checkCrawlConditions(targetState);
      LOG.debug("Backtracking by executing {} on element: {}", clickable.getEventType(),
              clickable);
      curState = changeState(targetState, clickable);
      handleInputElements(clickable);
      tryToFireEvent(targetState, curState, clickable);
      checkCrawlConditions(targetState);
    }

    if (!curState.equals(targetState)) {
      throw new StateUnreachableException(targetState,
              "The path didn't result in the desired state but in state "
                      + curState.getName());
    }
  }
View Full Code Here

  private StateVertex changeState(StateVertex targetState, Eventable clickable) {
    boolean switched = stateMachine.changeState(clickable.getTargetStateVertex());
    if (!switched) {
      throw new StateUnreachableException(targetState, "Could not switch states");
    }
    StateVertex curState = clickable.getTargetStateVertex();
    crawlpath.add(clickable);
    return curState;
  }
View Full Code Here

  private void inspectNewState(Eventable event) {
    if (crawlerLeftDomain()) {
      LOG.debug("The browser left the domain. Going back one state...");
      goBackOneState();
    } else {
      StateVertex newState = stateMachine.newStateFor(browser);
      if (domChanged(event, newState)) {
        inspectNewDom(event, newState);
      } else {
        LOG.debug("Dom unchanged");
      }
View Full Code Here

      context.getSession().addCrawlPath(crawlpath.immutableCopy());
    }
  }

  private void parseCurrentPageForCandidateElements() {
    StateVertex currentState = stateMachine.getCurrentState();
    LOG.debug("Parsing DOM of state {} for candidate elements", currentState.getName());
    ImmutableList<CandidateElement> extract = candidateExtractor.extract(currentState);
   
    plugins.runPreStateCrawlingPlugins(context, extract, currentState);
    candidateActionCache.addActions(extract, currentState);
  }
View Full Code Here

  private void goBackOneState() {
    LOG.debug("Going back one state");
    CrawlPath currentPath = crawlpath.immutableCopy();
    crawlpath = null;
    StateVertex current = stateMachine.getCurrentState();
    reset();
    follow(currentPath, current);
  }
View Full Code Here

TOP

Related Classes of com.crawljax.core.state.StateVertex

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.