Search in sources :

Example 1 with Scenario

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

the class JUnitDescriptionGenerator method insertDescriptionForExamples.

private void insertDescriptionForExamples(PerformableScenario performableScenario, Description scenarioDescription) {
    Scenario scenario = performableScenario.getScenario();
    for (ExamplePerformableScenario examplePerformableScenario : performableScenario.getExamples()) {
        Description exampleRowDescription = Description.createSuiteDescription(configuration.keywords().examplesTableRow() + " " + examplePerformableScenario.getParameters());
        scenarioDescription.addChild(exampleRowDescription);
        if (hasGivenStories(scenario)) {
            insertGivenStories(scenario, exampleRowDescription);
        }
        addScenarioSteps(ScenarioType.EXAMPLE, scenario, exampleRowDescription);
    }
}
Also used : Description(org.junit.runner.Description) ExamplePerformableScenario(org.jbehave.core.embedder.PerformableTree.ExamplePerformableScenario) PerformableScenario(org.jbehave.core.embedder.PerformableTree.PerformableScenario) Scenario(org.jbehave.core.model.Scenario) ExamplePerformableScenario(org.jbehave.core.embedder.PerformableTree.ExamplePerformableScenario)

Example 2 with Scenario

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

the class RegexStoryParserBehaviour method shouldParseLongStory.

@Test
public void shouldParseLongStory() {
    String aGivenWhenThen = "Given a step" + NL + "When I run it" + NL + "Then I should seen an output" + NL;
    StringBuffer aScenario = new StringBuffer();
    aScenario.append("Scenario: A long scenario").append(NL);
    int numberOfGivenWhenThensPerScenario = 50;
    for (int i = 0; i < numberOfGivenWhenThensPerScenario; i++) {
        aScenario.append(aGivenWhenThen);
    }
    int numberOfScenarios = 100;
    StringBuffer wholeStory = new StringBuffer();
    wholeStory.append("Story: A very long story").append(NL);
    for (int i = 0; i < numberOfScenarios; i++) {
        wholeStory.append(aScenario).append(NL);
    }
    Story story = parser.parseStory(wholeStory.toString(), null);
    assertThat(story.getScenarios().size(), equalTo(numberOfScenarios));
    for (Scenario scenario : story.getScenarios()) {
        assertThat(scenario.getSteps().size(), equalTo(numberOfGivenWhenThensPerScenario * 3));
    }
}
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)

Example 3 with Scenario

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

the class RegexStoryParserBehaviour method shouldParseStoryWithLifecycleAfterUponOutcome.

@Test
public void shouldParseStoryWithLifecycleAfterUponOutcome() {
    String wholeStory = "Lifecycle: " + NL + "After:" + NL + NL + "Outcome: ANY " + NL + "Given a step after any scenario" + NL + "Outcome: SUCCESS " + NL + "Given a step after successful scenario" + NL + "Outcome: FAILURE " + NL + "Given a step after failed scenario" + NL + "Scenario:" + NL + "Given a scenario";
    Story story = parser.parseStory(wholeStory, storyPath);
    List<String> beforeSteps = story.getLifecycle().getBeforeSteps();
    assertThat(beforeSteps.isEmpty(), equalTo(true));
    Lifecycle lifecycle = story.getLifecycle();
    List<String> afterSteps = lifecycle.getAfterSteps();
    assertThat(afterSteps.get(0), equalTo("Given a step after any scenario"));
    assertThat(afterSteps.get(1), equalTo("Given a step after successful scenario"));
    assertThat(afterSteps.get(2), equalTo("Given a step after failed scenario"));
    assertThat(lifecycle.getAfterSteps(Outcome.ANY).size(), equalTo(1));
    assertThat(lifecycle.getAfterSteps(Outcome.ANY).get(0), equalTo("Given a step after any scenario"));
    assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS).size(), equalTo(1));
    assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS).get(0), equalTo("Given a step after successful scenario"));
    assertThat(lifecycle.getAfterSteps(Outcome.FAILURE).size(), equalTo(1));
    assertThat(lifecycle.getAfterSteps(Outcome.FAILURE).get(0), equalTo("Given a step after failed scenario"));
    Scenario scenario = story.getScenarios().get(0);
    List<String> steps = scenario.getSteps();
    assertThat(steps.get(0), equalTo("Given a scenario"));
}
Also used : Lifecycle(org.jbehave.core.model.Lifecycle) 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)

Example 4 with Scenario

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

the class RegexStoryParserBehaviour method shouldParseStoryWithMetaAndNarrative.

@Test
public void shouldParseStoryWithMetaAndNarrative() {
    String wholeStory = "Meta: @skip @theme parsing" + NL + "Narrative: This bit of text is ignored" + NL + "In order to renovate my house" + NL + "As a customer" + NL + "I want to get a loan" + NL + "Scenario: A scenario" + NL + "Meta: @author Mauro" + NL + "Given a step " + NL + "Scenario: Another scenario" + NL + "Meta: @author Paul" + NL + "Given another step ";
    Story story = parser.parseStory(wholeStory, storyPath);
    assertThat(story.getPath(), equalTo(storyPath));
    Meta storyMeta = story.getMeta();
    assertThat(storyMeta.getProperty("theme"), equalTo("parsing"));
    assertThat(storyMeta.getProperty("skip"), equalTo(EMPTY));
    assertThat(storyMeta.getProperty("unknown"), equalTo(EMPTY));
    Narrative narrative = story.getNarrative();
    assertThat(narrative.isEmpty(), not(true));
    List<Scenario> scenarios = story.getScenarios();
    assertThat(scenarios.get(0).getTitle(), equalTo("A scenario"));
    assertThat(scenarios.get(0).getMeta().getProperty("author"), equalTo("Mauro"));
    assertThat(scenarios.get(1).getTitle(), equalTo("Another scenario"));
    assertThat(scenarios.get(1).getMeta().getProperty("author"), equalTo("Paul"));
}
Also used : Meta(org.jbehave.core.model.Meta) Narrative(org.jbehave.core.model.Narrative) 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)

Example 5 with Scenario

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

the class RegexStoryParserBehaviour method shouldParseStoryWithLifecycleBeforeOnly.

@Test
public void shouldParseStoryWithLifecycleBeforeOnly() {
    String wholeStory = "Lifecycle: " + NL + "Before:" + NL + NL + "Given a step before each scenario" + NL + "And another before step" + NL + "Scenario:" + NL + "Given a scenario";
    Story story = parser.parseStory(wholeStory, storyPath);
    List<String> beforeSteps = story.getLifecycle().getBeforeSteps();
    assertThat(beforeSteps.get(0), equalTo("Given a step before each scenario"));
    assertThat(beforeSteps.get(1), equalTo("And another before step"));
    List<String> afterSteps = story.getLifecycle().getAfterSteps();
    assertThat(afterSteps.isEmpty(), equalTo(true));
    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