Why don't you then set the context up once using @BeforeStories?
On 02/08/2012 13:00, Ádám Csordás wrote:
Hi,
As I understand from your answer the BeforeStory methods are collected
together before the run of the main story and they executed together.
This is a problem for me because a selenium context is initialized in
my the BeforeStory methods.
The first given story is a long running test and it cause selenium
timeout in the second test. Increasing the value of timeout is not an
option yet. Now I am looking for a solution to run the selenium
context initialization just before the story run. I have tried
BeforeStory, BeforeScenario and BeforeClass annotations, but neither
of them was good for me. Any idea on this?
BR,
Adam
------------------------------------------------------------------------
*From:* Mauro Talevi [mailto:[email protected]]
*Sent:* Thursday, August 02, 2012 11:16 AM
*To:* [email protected]
*Subject:* Re: [jbehave-user] BeforeStory annotation problem when
GivenStories is used
Hi,
given stories are treated as independent stories, as far the
before/after annotations go. We could introduce an optional flag
that would distinguish between methods that are executed only for
given stories. But this would not solve all the issues you may
have. I think there is a glass ceiling in using the before/after
annotations if you're trying to execute repeated behaviour. I find
that often using explicit steps, possibly abstracted in a setup story
that you can invoke via GivenStories may be a better practice than
using a @BeforeStory annotated method. Remember that the annotated
before/after methods are not visible to the story writers so they
should be used with care.
Also, the before/after annotated methods are collected and executed
all together so it's at present not at all easy to correlate one
against the other, nor is it possible to pass parameters. For that,
parametrised steps in scenarios are better. Amongst other things, you
can use meta parameters to tag a story as a given story and adapt the
behaviour accordingly.
Alternatively, you may try to keep state in your @BeforeStory
implementation class using the @AfterStory as well to determine if
you're running a given story or not.
Hope this helps. If you want to provide more details on your specific
scenario, perhaps we can provide a more specific solution.
Cheers
On 02/08/2012 10:06, Ádám Csordás wrote:
Hi,
I have created a story that has GivenStories block with two stories.
Both given story has a method annotated with BeforeStory. When the
main story runs both BeforeStory method is called before each given
story, which cause me a problem. Also I think it is not the expected
behavior in this case. Dose anybody have a solution for this? Thanks
in advance.
Br,
Adam