private void runScenariosParametrisedByExamples( RunContext context, Scenario scenario, Lifecycle lifecycle, Meta storyAndScenarioMeta) throws Throwable { ExamplesTable table = scenario.getExamplesTable(); reporter.get().beforeExamples(scenario.getSteps(), table); Keywords keywords = context.configuration().keywords(); for (Map<String, String> scenarioParameters : table.getRows()) { Meta parameterMeta = parameterMeta(keywords, scenarioParameters); if (!parameterMeta.isEmpty() && !context.filter.allow(parameterMeta)) { continue; } reporter.get().example(scenarioParameters); if (context.configuration().storyControls().resetStateBeforeScenario()) { context.resetState(); } runBeforeOrAfterScenarioSteps( context, scenario, storyAndScenarioMeta, Stage.BEFORE, ScenarioType.EXAMPLE); runStepWithLifecycle(context, lifecycle, scenarioParameters, scenario, storyAndScenarioMeta); runBeforeOrAfterScenarioSteps( context, scenario, storyAndScenarioMeta, Stage.AFTER, ScenarioType.EXAMPLE); } reporter.get().afterExamples(); }
private void runCancellable(RunContext context, Story story, Map<String, String> storyParameters) throws Throwable { if (!context.givenStory()) { reporter.set(reporterFor(context, story)); } pendingStepStrategy.set(context.configuration().pendingStepStrategy()); failureStrategy.set(context.configuration().failureStrategy()); resetStoryFailure(context); if (context.dryRun()) { reporter.get().dryRun(); } if (context.configuration().storyControls().resetStateBeforeStory()) { context.resetState(); } // run before story steps, if any reporter.get().beforeStory(story, context.givenStory()); boolean storyAllowed = true; FilteredStory filterContext = context.filter(story); Meta storyMeta = story.getMeta(); if (!filterContext.allowed()) { reporter.get().storyNotAllowed(story, context.metaFilterAsString()); storyAllowed = false; } if (storyAllowed) { reporter.get().narrative(story.getNarrative()); runBeforeOrAfterStorySteps(context, story, Stage.BEFORE); addMetaParameters(storyParameters, storyMeta); runGivenStories(story.getGivenStories(), storyParameters, context); // determine if before and after scenario steps should be run boolean runBeforeAndAfterScenarioSteps = shouldRunBeforeOrAfterScenarioSteps(context); reporter.get().lifecyle(story.getLifecycle()); for (Scenario scenario : story.getScenarios()) { // scenario also inherits meta from story boolean scenarioAllowed = true; if (failureOccurred(context) && context.configuration().storyControls().skipScenariosAfterFailure()) { continue; } reporter.get().beforeScenario(scenario.getTitle()); reporter.get().scenarioMeta(scenario.getMeta()); if (!filterContext.allowed(scenario)) { reporter.get().scenarioNotAllowed(scenario, context.metaFilterAsString()); scenarioAllowed = false; } if (scenarioAllowed) { if (context.configuration().storyControls().resetStateBeforeScenario()) { context.resetState(); } Meta storyAndScenarioMeta = scenario.getMeta().inheritFrom(storyMeta); // run before scenario steps, if allowed if (runBeforeAndAfterScenarioSteps) { runBeforeOrAfterScenarioSteps( context, scenario, storyAndScenarioMeta, Stage.BEFORE, ScenarioType.NORMAL); } if (isParameterisedByExamples(scenario)) { // run parametrised scenarios by examples runScenariosParametrisedByExamples( context, scenario, story.getLifecycle(), storyAndScenarioMeta); } else { // run as plain old scenario runStepWithLifecycle( context, story.getLifecycle(), storyParameters, scenario, storyAndScenarioMeta); } // run after scenario steps, if allowed if (runBeforeAndAfterScenarioSteps) { runBeforeOrAfterScenarioSteps( context, scenario, storyAndScenarioMeta, Stage.AFTER, ScenarioType.NORMAL); } } reporter.get().afterScenario(); } // run after story steps, if any runBeforeOrAfterStorySteps(context, story, Stage.AFTER); } reporter.get().afterStory(context.givenStory()); // handle any failure according to strategy if (!context.givenStory()) { handleStoryFailureByStrategy(); } }