Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@BeforeScenario / @AfterScenario to Specific Scenario in Test Story by using Given

Tags:

jbehave

I am a newbie to JBheave and Hive frameworks.

While exploring Q&A repositories, I happen to see the following phrase from one of right Answer to a Question,-

writing a JBehave story

That's what I've seen - and the data object should be setup/cleared with a @BeforeScenario/@AfterScenario method.

At present I am in the process of writing Test Stories. Yet not get into Steps further.

From the JBehave product website, I get the following sample Test Story. I have Question considering the phrase which I plugged out from the Q&A repo of StackOverFlow.

A story is a collection of scenarios

Narrative:
In order to communicate effectively to the business some functionality
As a development team
I want to use Behaviour-Driven Development

Lifecycle:
Before:
Given a step that is executed before each scenario
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

Scenario:  A scenario is a collection of executable steps of different type

Given step represents a precondition to an event
When step represents the occurrence of the event
Then step represents the outcome of the event

Scenario:  Another scenario exploring different combination of events

Given a [precondition]
When a negative event occurs
Then a the outcome should [be-captured]   

Examples:
|precondition|be-captured|
|abc|be captured    |
|xyz|not be captured|

I could see the pretty same just as like @BeforeScenario/@AfterScenario over here.

I do have Question here. Is I could write Given before and after to specific Scenario: in a Test Story.

And is that Scenario: output is open to consecutive Scenario:'s in the Test Story.

like image 327
Dev Anand Sadasivam Avatar asked Feb 26 '16 07:02

Dev Anand Sadasivam


1 Answers

There is a few differences between @BeforeScenario/@AfterScenario annotations and Lifecycle:Before/After steps

  1. A java method annotated with @BeforeScenario or @AfterScenario is called for all executed scenarios in all stories, while a Lifecycle-Before or -After step will be executed only for scenarios from this one, concrete story.
  2. @AfterScenario method is executed always, regardless of a result of the scenario. Lifecycle After steps can be called always (using Outcome: ANY clause), only on failures (using Outcome: Failure clause) or only on success (using Outcome: SUCCESS clause)
  3. You cannot pass any parameters from a scenario (story) to @BeforeScenario and @AfterScenario java methods, while Lifecycle steps can have parameters, like any other ordinary steps, for example:

Lifecycle:
Before:
Given a step that is executed before each scenario with some parameter = 2
like image 143
krokodilko Avatar answered Oct 07 '22 14:10

krokodilko