Reputation: 1361
When using Serenity with JBehave, my step definition adds information provided through @Given and @When into an internal state class, which is validated in @Then methods.
The state class needs to be reinitialized for each test, that is before each scenario without example and before each example of a scenario with examples.
How can I achieve that?
I found a JIRA ticket requesting @BeforeExample (which would solve my problem) at http://jbehave.github.io/Old_JBehave_Issues/548/. However, using @BeforeScenario clears only before each scenario, but not before each example.
Clearing state in each @Given would not work in the cases where a scenario has multiple @Givens (using Given... And....).
Upvotes: 0
Views: 1495
Reputation: 1
Old post, but if someone get's here, know that there is already a @BeforeExample and @AfterExample annotation for this purpose
Upvotes: 0
Reputation: 420
You might try to reset scenario-state using JBehave's 'Before' LifeCycle:
Narrative:
...
Lifecycle:
Before:
Given a step that is executed before each scenario
Some additional Lifecycle options:
Lifecycle:
After:
Outcome: ANY
Given a step that is executed after each scenario regardless of outcome
Outcome: SUCCESS
Given a step that is executed after each successful scenario
Outcome: FAILURE
Given a step that is executed after each failed scenario
Source: JBehave Story Syntax
Upvotes: 0
Reputation: 1361
@BeforeScenario
does not work (is ignored for scenarios with examples alltogether).
@BeforeScenario(uponType = ScenarioType.ANY)
does work, which I found not working before posting this question, but was apparently caused by another reason.
Either way, the method must be public.
Upvotes: 0