[Cucumber-JVM] How to obtain reference to scenario object in step definitions

918 views
Skip to first unread message

Yogesh Aggarwal

unread,
Feb 7, 2013, 2:11:12 AM2/7/13
to cu...@googlegroups.com
Currently we have a reference to Scenario object in @After hook only.

Can we have a reference to this static Scenario object in my step definition class (other than @After hook) so that I use Scenario.write in any of my step definition class?

Thanks!

aslak hellesoy

unread,
Feb 7, 2013, 2:21:03 AM2/7/13
to Cucumber Users
On Thu, Feb 7, 2013 at 7:11 AM, Yogesh Aggarwal <yogesh70...@gmail.com> wrote:
Currently we have a reference to Scenario object in @After hook only.

Can we have a reference to this static Scenario object in my step definition class (other than @After hook) so that I use Scenario.write in any of my step definition class?


I wouldn't do that, there is a new instance created before each scenario, and holding on to old ones in static fields is guaranteed to mess things up.

Any class that defines an @After hook can get a reference to the Scenario passed in. Why don't you just add an @After to each class that needs a ref to the Scenario?

Aslak
 
Thanks!

--
-- Rules --
 
1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.
 
You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cu...@googlegroups.com. To unsubscribe from this group, send email to cukes+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Yogesh Aggarwal

unread,
Feb 7, 2013, 2:27:17 AM2/7/13
to cu...@googlegroups.com


On Thursday, February 7, 2013 12:51:03 PM UTC+5:30, Aslak Hellesøy wrote:



On Thu, Feb 7, 2013 at 7:11 AM, Yogesh Aggarwal <yogesh70...@gmail.com> wrote:
Currently we have a reference to Scenario object in @After hook only.

Can we have a reference to this static Scenario object in my step definition class (other than @After hook) so that I use Scenario.write in any of my step definition class?


I wouldn't do that, there is a new instance created before each scenario, and holding on to old ones in static fields is guaranteed to mess things up.

Any class that defines an @After hook can get a reference to the Scenario passed in. Why don't you just add an @After to each class that needs a ref to the Scenario?

Aslak

Can we have multiple @After hooks?
If yes, then do all of them execute after then scenario? How do we get a control of their execution?

aslak hellesoy

unread,
Feb 7, 2013, 2:38:33 AM2/7/13
to Cucumber Users
On Thu, Feb 7, 2013 at 7:27 AM, Yogesh Aggarwal <yogesh70...@gmail.com> wrote:


On Thursday, February 7, 2013 12:51:03 PM UTC+5:30, Aslak Hellesøy wrote:



On Thu, Feb 7, 2013 at 7:11 AM, Yogesh Aggarwal <yogesh70...@gmail.com> wrote:
Currently we have a reference to Scenario object in @After hook only.

Can we have a reference to this static Scenario object in my step definition class (other than @After hook) so that I use Scenario.write in any of my step definition class?


I wouldn't do that, there is a new instance created before each scenario, and holding on to old ones in static fields is guaranteed to mess things up.

Any class that defines an @After hook can get a reference to the Scenario passed in. Why don't you just add an @After to each class that needs a ref to the Scenario?

Aslak

Can we have multiple @After hooks?

Yes
 
If yes, then do all of them execute after then scenario?

Yes, all of them will run after the scenario.
 
How do we get a control of their execution?

Via the order attribute. See the Javadocs.

I just realised the stylesheets are broken, so it's a little hard to read. I have created a ticket for that: https://github.com/cucumber/cucumber-jvm/issues/457

Aslak
Reply all
Reply to author
Forward
0 new messages