예제 #1
0
  private void runScenarios(
      ExecutionToken executionToken,
      FeatureToken feature,
      List<ScenarioToken> scenarios,
      HandlerManager handlerManager)
      throws Exception {
    log.debug("Now running scenarios " + scenarios + " for feature " + feature);
    for (Iterator<ScenarioToken> iterator = scenarios.iterator(); iterator.hasNext(); ) {
      ScenarioToken scenario = iterator.next();

      // if the feature start scenario exists and failed we skip all but feature end scenario
      boolean skip =
          !scenario.isFeatureStartScenario()
              && !scenario.isFeatureEndScenario()
              && feature.isFeatureStartScenarioFailed();

      if (skip) {
        log.warn(
            "Skipping scenario "
                + scenario
                + " since "
                + KeyWord.FEATURE_START_SCENARIO_NAME
                + " failed");
      }

      runScenario(executionToken, handlerManager, scenario, skip);
    }
  }
예제 #2
0
  private void runFeature(ExecutionToken executionToken, FeatureToken feature) {

    executionListenerSupport.notifyFeatureStarted(executionToken, feature);
    // notify we started, even if there are missing handlers
    // (but nothing will be done)
    // this is still important so execution listeners at least see the feature (but will show as
    // 'unimplemented')
    String config = feature.isConfiguration() ? " in config " + feature.getConfigurationName() : "";
    log.info("Running feature from file: " + feature.getFeatureFile() + config);

    // check that the required handler classes are all available and list them in order of
    // precedence
    List<Class> orderedHandlerClasses = new ArrayList<>();
    StringBuilder unavailableHandlersMessage =
        handlerClassDiscovery.findHandlerClasses(allHandlerClasses, feature, orderedHandlerClasses);
    boolean foundAllHandlerClasses = unavailableHandlersMessage.length() == 0;

    // run the scenarios in the feature
    if (foundAllHandlerClasses) {
      log.debug("The following handlers will be used " + orderedHandlerClasses);
      List<ScenarioToken> scenarios = feature.getScenarios();

      try {
        HandlerManager handlerManager =
            new HandlerManager(
                feature,
                orderedHandlerClasses,
                springContextSupport,
                subsystemManager,
                executionToken.getProfile());
        handlerManager.createFeatureScopedHandlers();
        handlerManager.processStartOfFeature();

        runScenarios(executionToken, feature, scenarios, handlerManager);

        handlerManager.processEndOfFeature();
      } catch (Exception e) {
        log.error("Exception while running feature " + feature.getName(), e);
      }

      String description =
          feature.getEndState() == EndState.PASSED
              ? " passed! "
              : feature.getEndState() == EndState.PENDING ? " pending! " : " failed! ";
      log.trace("The feature " + description);

      if (feature.getEndState() == EndState.PASSED) {
        executionToken.incrementFeaturesPassed();
      } else if (feature.getEndState() == EndState.PENDING) {
        executionToken.incrementFeaturesPending();
      } else {
        executionToken.incrementFeaturesFailed();
      }
    } else {
      log.warn(
          "The following handlers were not available, failing feature "
              + feature.getName()
              + " "
              + unavailableHandlersMessage);
      feature.setUnavailableHandlersMessage(unavailableHandlersMessage.toString());
      executionToken.incrementUnavailableHandlers();
      executionToken.incrementFeaturesFailed();
    }

    executionListenerSupport.notifyFeatureCompleted(executionToken, feature);
  }