I had a similar use case and we did the following:

*         Defined all the @Before/After annotations in a LifecycleSteps class 
that extends org.jbehave.web.selenium.PerStoryWebDriverSteps

*         These steps can take the Meta tags as input. Hence we define a meta 
that looks like "@resetAcctPolsToDefaulsOnFailure true" for the scenarios in 
which we wanted to reset

*         Inside the method we check if this is defined and true and then do 
the resetting

Our code looks something like this
@AfterScenario(uponOutcome=Outcome.FAILURE)
public void 
resetAcctPolsToDefaulsOnFailure(@Named("resetAcctPolsToDefaulsOnFailure")String 
resetAcctPolsToDefaulsOnFailure) {
     logger.debug("[resetAcctPolsToDefaulsOnFailure] Scenario failed inside");
     if(new Boolean(resetVipAcctPolsToDefaulsOnFailure)) {
           logger.info("[resetVipAcctPolsToDefaulsOnFailure] Reseting VIP 
Account tab policies back to default");
//resetting code here
     }
     else
           logger.debug("[resetAcctPolsToDefaulsOnFailure] MetaTag 
resetVipAcctPolsToDefaulsOnFailure [{}] NOT RESETING VIP Account tab policies 
back to default", resetVipAcctPolsToDefaulsOnFailure);
}


Thanks,
Enrique

From: Mauro Talevi [mailto:[email protected]]
Sent: Monday, January 27, 2014 12:35 PM
To: [email protected]
Subject: Re: [jbehave-user] Reset State in Parameterized Scenario

Hi,

the @Before/After annotations are not able to take any runtime parameters.

If you want to reset after a single parametrised scenario then you can simply 
define a reset step and make it part of the scenario.

Cheers

On 27/01/2014 15:26, Corbin, J.D. wrote:
Hi Mauro,

Thanks for that suggestion.  It happens to work in my case since I only have 
one parameterized scenario, but what if I had two and only wanted the reset 
behavior for a single parameterized scenario.  Is that possible?  I would think 
the scenario would have to be named in some way.

J.D.

On Sat, Jan 25, 2014 at 2:21 AM, Mauro Talevi 
<[email protected]<mailto:[email protected]>> wrote:
Use annotation specifying the scenario type

@BeforeScenario(uponType=ScenarioType.EXAMPLE)

Cheers


On 24/01/2014 23:14, Corbin, J.D. wrote:
We are using the tabular scenario format to run multiple sets of data through a 
single jbehave scenario using the Examples: tabular format.

We are using a custom scenario scope that has our global scenario state.  Using 
this approach, we get a new instance of our global state object at the 
beginning of each scenario which is what we want.

The problem is that there is some state we'd like to reset in between the 
tabular runs for the scenario but I don't see where to inject some behavior 
into JBehave.  JBehave doesn't treat each run as a new scenario, just runs the 
new set of parameterized data through the same scenario instance, so we cannot 
figure out where to reset the state in between the runs.  We have gotten around 
this by resetting the state in one of the steps of the scenario but this is not 
ideal because its possible that this step is used in other scenarios and we 
don't necessary want this state reset in those cases.

Is there such a thing as tabular scope or some place we can introduce some 
behavior in between parameterized runs of a single scenario?

J.D.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply via email to