Search in sources :

Example 16 with Scenario

use of org.jbehave.core.model.Scenario in project jbehave-core by jbehave.

the class GherkinStoryParserBehaviour method shouldParseStoryWithTags.

@Test
public void shouldParseStoryWithTags() throws IOException {
    String storyAsText = "@feature\n" + "Feature: Hello Car\n\n" + "Background:\n" + "Given I have a license\n\n" + "@scenario\n" + "Scenario: Car can drive\n" + "Given I have a car with 4 wheels\n" + "Then I can drive it.\n";
    Story story = storyParser.parseStory(storyAsText);
    assertThat(story.getDescription().asString(), equalTo("Hello Car"));
    assertThat(story.getMeta().hasProperty("feature"), Matchers.is(true));
    Scenario scenario = story.getScenarios().get(0);
    assertThat(scenario.getSteps().size(), equalTo(2));
    assertThat(scenario.getMeta().hasProperty("scenario"), Matchers.is(true));
}
Also used : Story(org.jbehave.core.model.Story) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 17 with Scenario

use of org.jbehave.core.model.Scenario in project jbehave-core by jbehave.

the class GherkinStoryParserBehaviour method shouldParseStoryWithExamples.

@Test
public void shouldParseStoryWithExamples() throws IOException {
    String storyAsText = "Feature: Hello Car\n" + "@scenarioOutline\n" + "Scenario Outline: Car can drive\n" + "Given I have a car\n" + "When I add <wheels>\n" + "Then It <can_drive>\n" + "\n" + "Examples:\n" + "| wheels | can_drive |\n" + "| 1 | false |\n" + "| 2 | false |\n" + "| 3 | false |\n" + "| 4 | true |";
    Story story = storyParser.parseStory(storyAsText);
    assertThat(story.getDescription().asString(), equalTo("Hello Car"));
    List<Scenario> scenarios = story.getScenarios();
    assertThat(scenarios.size(), equalTo(1));
    Scenario scenario = scenarios.get(0);
    List<String> steps = scenario.getSteps();
    assertThat(scenario.getTitle(), equalTo("Car can drive"));
    assertThat(scenario.getMeta().hasProperty("scenarioOutline"), Matchers.is(true));
    assertThat(steps.size(), equalTo(3));
    assertThat(steps.get(0), equalTo("Given I have a car"));
    assertThat(steps.get(1), equalTo("When I add <wheels>"));
    assertThat(steps.get(2), equalTo("Then It <can_drive>"));
    assertThat(scenario.getExamplesTable().asString(), equalTo("|wheels|can_drive|\n" + "|1|false|\n" + "|2|false|\n" + "|3|false|\n" + "|4|true|\n"));
}
Also used : Story(org.jbehave.core.model.Story) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 18 with Scenario

use of org.jbehave.core.model.Scenario in project jbehave-core by jbehave.

the class StoryRunner method runCancellable.

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);
            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
                    runStepsWithLifecycle(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();
    }
}
Also used : Meta(org.jbehave.core.model.Meta) Scenario(org.jbehave.core.model.Scenario)

Example 19 with Scenario

use of org.jbehave.core.model.Scenario in project serenity-jbehave by serenity-bdd.

the class JUnitDescriptionGenerator method createDescriptionFrom.

public Description createDescriptionFrom(PerformableScenario performableScenario) {
    Scenario scenario = performableScenario.getScenario();
    Description scenarioDescription = createDescriptionForScenario(scenario);
    if (performableScenario.hasExamples() && !scenario.getGivenStories().requireParameters()) {
        insertDescriptionForExamples(performableScenario, scenarioDescription);
    } else {
        if (hasGivenStories(scenario)) {
            insertGivenStories(scenario, scenarioDescription);
        }
        addScenarioSteps(ScenarioType.NORMAL, scenario, scenarioDescription);
    }
    return scenarioDescription;
}
Also used : Description(org.junit.runner.Description) PerformableScenario(org.jbehave.core.embedder.PerformableTree.PerformableScenario) Scenario(org.jbehave.core.model.Scenario) ExamplePerformableScenario(org.jbehave.core.embedder.PerformableTree.ExamplePerformableScenario)

Example 20 with Scenario

use of org.jbehave.core.model.Scenario in project jbehave-core by jbehave.

the class RegexStoryParserBehaviour method shouldParseStoryWithLifecycleAndStoryScope.

@Test
public void shouldParseStoryWithLifecycleAndStoryScope() {
    String wholeStory = "Lifecycle: " + NL + "Before:" + NL + NL + "Scope: STORY" + NL + "Given a step before each story" + NL + "And another before story" + NL + "After:" + NL + NL + "Scope: STORY" + NL + "Given a step after each story" + NL + "And another after story" + NL + "Scenario:" + NL + "Given a scenario";
    Story story = parser.parseStory(wholeStory, storyPath);
    assertThat(story.getLifecycle().hasBeforeSteps(), is(true));
    List<String> beforeSteps = story.getLifecycle().getBeforeSteps(Scope.STORY);
    assertThat(beforeSteps.get(0), equalTo("Given a step before each story"));
    assertThat(beforeSteps.get(1), equalTo("And another before story"));
    assertThat(story.getLifecycle().getBeforeSteps(Scope.SCENARIO).size(), equalTo(0));
    assertThat(story.getLifecycle().hasAfterSteps(), is(true));
    List<String> afterSteps = story.getLifecycle().getAfterSteps(Scope.STORY);
    assertThat(afterSteps.get(0), equalTo("Given a step after each story"));
    assertThat(afterSteps.get(1), equalTo("And another after story"));
    assertThat(story.getLifecycle().getAfterSteps(Scope.SCENARIO).size(), equalTo(0));
    Scenario scenario = story.getScenarios().get(0);
    List<String> steps = scenario.getSteps();
    assertThat(steps.get(0), equalTo("Given a scenario"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Aggregations

Scenario (org.jbehave.core.model.Scenario)35 Story (org.jbehave.core.model.Story)29 Test (org.junit.Test)27 Matchers.containsString (org.hamcrest.Matchers.containsString)20 GivenStory (org.jbehave.core.model.GivenStory)20 Meta (org.jbehave.core.model.Meta)9 ExamplesTable (org.jbehave.core.model.ExamplesTable)5 GivenStories (org.jbehave.core.model.GivenStories)5 Lifecycle (org.jbehave.core.model.Lifecycle)5 UUIDExceptionWrapper (org.jbehave.core.failures.UUIDExceptionWrapper)4 LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)3 Narrative (org.jbehave.core.model.Narrative)3 InOrder (org.mockito.InOrder)3 HashMap (java.util.HashMap)2 ExamplePerformableScenario (org.jbehave.core.embedder.PerformableTree.ExamplePerformableScenario)2 PerformableScenario (org.jbehave.core.embedder.PerformableTree.PerformableScenario)2 Description (org.jbehave.core.model.Description)2 OutcomesTable (org.jbehave.core.model.OutcomesTable)2 Description (org.junit.runner.Description)2 File (java.io.File)1