Cucumber-JVM: Hooks at a higher level

378 views
Skip to first unread message

Robert

unread,
Sep 2, 2011, 11:50:00 AM9/2/11
to cu...@googlegroups.com
I'd like to know if there is way currently built-in to Cucumber-JVM whereby I can globally create an object before any scenario is executed.  I'm aware of the @Before annotation, but that seems to work before each scenario.  I'm looking for something at a higher level -- possbily, something like @BeforeAll.  I understand that Cucumber (Ruby version) has at its disposal an env.rb file, which bootstraps and configures the Cucumber runner environment.  What I'm after is a way I might be able to create a WebDriver object just once and then share it among the different step definition classes.  Currently, we are using something like

    @Before
    public void startBrowser() {
        driver = new FirefoxDriver();
    }
   
    @After
    public void quitBrowser() {
        driver.quit();
    }   

for each of our step definitions.  However, this results in Selenium opening a new web brower window for each scenario.  Is this even possible? If so, please provide some examples of how I may implement it.  Thanks.

aslak hellesoy

unread,
Sep 2, 2011, 12:03:14 PM9/2/11
to cu...@googlegroups.com
On Fri, Sep 2, 2011 at 4:50 PM, Robert <rest...@gmail.com> wrote:
> I'd like to know if there is way currently built-in to Cucumber-JVM whereby
> I can globally create an object before any scenario is executed.

Not in Cucumber-JVM, but in Java itself.

Use a static field.

You can kill it before the JVM exits in a shutDownHook that you set up
in a static initializer.
http://download.oracle.com/javase/1,5.0/docs/guide/lang/hook-design.html

Aslak

> I'm aware
> of the @Before annotation, but that seems to work before each scenario.  I'm
> looking for something at a higher level -- possbily, something like
> @BeforeAll.  I understand that Cucumber (Ruby version) has at its disposal
> an env.rb file, which bootstraps and configures the Cucumber runner
> environment.  What I'm after is a way I might be able to create a WebDriver
> object just once and then share it among the different step definition
> classes.  Currently, we are using something like
>
>     @Before
>     public void startBrowser() {
>         driver = new FirefoxDriver();
>     }
>
>     @After
>     public void quitBrowser() {
>         driver.quit();
>     }
>
> for each of our step definitions.  However, this results in Selenium opening
> a new web brower window for each scenario.  Is this even possible? If so,
> please provide some examples of how I may implement it.  Thanks.
>

> --
> You received this message because you are subscribed to the Google Groups
> "Cukes" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/cukes/-/C_8Wu6FDWzUJ.
> 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
> http://groups.google.com/group/cukes?hl=en.
>

Reply all
Reply to author
Forward
0 new messages