JBehave
  1. JBehave
  2. JBEHAVE-429

@AfterScenario should execute in reverse order to @BeforeScenario

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.2
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Consider WebDriver situations, where the order below is nearly always going to be the case:

      new PerStoriesWebDriverSteps(..),
      new PerStoriesContextView(..),
      new WebDriverScreenshotOnFailure(..)

      If we change from PerStoriesWebDriverSteps to PerScenarioWebDriverSteps, then we have a problem. PerScenarioWebDriverSteps could conceivable drop the reference to WebDriver after closing it, and cause WebDriverScreenshotOnFailure to fail when it's needing to leap into action.

      The reproduction involved making steps fail, and making the PerStoriesWebDriverSteps to PerScenarioWebDriverSteps change.

        Activity

        Hide
        Paul Hammant added a comment -

        The following will do it. There's no broken unit-tests for this
        I can confirm that the purposefully broken Etsy (Cart can't find selector) with a change to PerScenarioWebDriver works as would be hoped for.

        .......................

        — a/jbehave-core/src/main/java/org/jbehave/core/steps/MarkUnmatchedStepsAsPending.java
        +++ b/jbehave-core/src/main/java/org/jbehave/core/steps/MarkUnmatchedStepsAsPending.java
        @@ -44,15 +44,17 @@ public class MarkUnmatchedStepsAsPending implements StepCollector {
        }

        public List<Step> collectBeforeOrAfterScenarioSteps(List<CandidateSteps> candidateSteps, Stage stage, boolean failureO

        • List<Step> steps = new ArrayList<Step>();
          + List<Step> beforeSteps = new ArrayList<Step>();
          + List<Step> afterSteps = new ArrayList<Step>();
          for (CandidateSteps candidates : candidateSteps) { List<BeforeOrAfterStep> beforeOrAfterScenarioSteps = candidates.listBeforeOrAfterScenario(); if (stage == Stage.BEFORE) - steps.addAll(createSteps(beforeOrAfterScenarioSteps, stage)); + beforeSteps.addAll(createSteps(beforeOrAfterScenarioSteps, stage)); else - steps.addAll(createStepsUponOutcome(beforeOrAfterScenarioSteps, stage, failureOccured)); + afterSteps.addAll(0, createStepsUponOutcome(beforeOrAfterScenarioSteps, stage, failureOccured)); }

          -
          + List<Step> steps = new ArrayList<Step>(beforeSteps);
          + steps.addAll(afterSteps);
          return steps;
          }

        Show
        Paul Hammant added a comment - The following will do it. There's no broken unit-tests for this I can confirm that the purposefully broken Etsy (Cart can't find selector) with a change to PerScenarioWebDriver works as would be hoped for. ....................... — a/jbehave-core/src/main/java/org/jbehave/core/steps/MarkUnmatchedStepsAsPending.java +++ b/jbehave-core/src/main/java/org/jbehave/core/steps/MarkUnmatchedStepsAsPending.java @@ -44,15 +44,17 @@ public class MarkUnmatchedStepsAsPending implements StepCollector { } public List<Step> collectBeforeOrAfterScenarioSteps(List<CandidateSteps> candidateSteps, Stage stage, boolean failureO List<Step> steps = new ArrayList<Step>(); + List<Step> beforeSteps = new ArrayList<Step>(); + List<Step> afterSteps = new ArrayList<Step>(); for (CandidateSteps candidates : candidateSteps) { List<BeforeOrAfterStep> beforeOrAfterScenarioSteps = candidates.listBeforeOrAfterScenario(); if (stage == Stage.BEFORE) - steps.addAll(createSteps(beforeOrAfterScenarioSteps, stage)); + beforeSteps.addAll(createSteps(beforeOrAfterScenarioSteps, stage)); else - steps.addAll(createStepsUponOutcome(beforeOrAfterScenarioSteps, stage, failureOccured)); + afterSteps.addAll(0, createStepsUponOutcome(beforeOrAfterScenarioSteps, stage, failureOccured)); } - + List<Step> steps = new ArrayList<Step>(beforeSteps); + steps.addAll(afterSteps); return steps; }
        Paul Hammant made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Paul Hammant [ paul ]
        Fix Version/s 3.2 [ 16757 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Paul Hammant
            Reporter:
            Paul Hammant
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: