Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'around all features' hook #84

Closed
peteclark82 opened this issue Aug 15, 2012 · 11 comments
Closed

Add 'around all features' hook #84

peteclark82 opened this issue Aug 15, 2012 · 11 comments

Comments

@peteclark82
Copy link

Hi,

It would be great if there was a hook available that could execute code before and after all the features have been run.

I am currently using WebDriver to automate browser testing. In order to speed things up, I am reusing a single browser instance that is available to each scenario. I therefore need to initialize the browser instance before the features are about to be run, and then close it down after they have finished.

I can't seem to find an elegant way to achieve this functionality at the moment. I have ended up invoking the CLI class directly from a custom Node app, and inserting my WebDriver init/shutdown code there.

Cheers
Pete

@jbpros
Copy link
Member

jbpros commented Aug 15, 2012

Do you mean a single around all hook or two separate before/after all hooks? Cucumber-ruby exposes two separate hooks: AfterConfiguration and at_exit. Would something similar suit your needs?

@peteclark82
Copy link
Author

Great, yeah, those hooks sound like they would do the job. I basically just need some way to launch the browser before the tests run, and then close it down afterwards.

@jmonschke
Copy link

It would also be good to have an around each Feature hook, as I am using WebDriver, and would like to utilize a single browser for each feature, but multiple scenarios.

@aslakhellesoy
Copy link
Contributor

I wouldn't add features to Cucumber-Js that are already available in the JavaScript platform (Node.js in this case):

module.exports = function() {
  this.Before(function(callback) {
    if(global.browser) {
      callback();
    } else {
      // create the browser and assign it to global.browser.
    }
  });
};

process.on('exit', function() {
  if(global.browser) {
    // kill it
  }
});

See "Global Hooks" at https://github.com/cucumber/cucumber/wiki/Hooks

@jbpros
Copy link
Member

jbpros commented Oct 29, 2012

@aslakhellesoy 😆 that's great.

However, in a browser context, it might be a bit trickier to set up. I have an idea as to how it can be achieved though. Let's close this and see if it comes back and bites us.

@jbpros jbpros closed this as completed Oct 29, 2012
@peteclark82
Copy link
Author

@aslakhellesoy

I had already tried this, but unfortunately by the time process.on('exit') is invoked, Node is no longer running the main event loop. This means that WebDriver's asynchronous operation of closing all browser windows is not always scheduled and executed.

@trevorrowe
Copy link

@aslakhellesoy @jbpros

I am running into a very similar issue. I have the need to perform some setup and cleanup once around all of the scenarios. It would be very costly to run the setup and clean around each scenario individually. It is fairly easy to get a Before hook to execute only once. It is not a simple process to get an After hook to execute only once after all scenarios are finished. It is not possible to use process.on('exit', ...), as the cleanup code is asynchronous.

Adding support for the equivalent Ruby cucumber hooks AfterConfiguration and at_exit could resolve this issue.

@jbpros
Copy link
Member

jbpros commented Nov 7, 2012

@trevorrowe @peteclark82 I hear you guys. Opened #97 for afterAll hook support.

@asrail
Copy link

asrail commented Mar 3, 2013

I have used the code above from @aslakhellesoy, but the global is undefined for every scenario.
It is in coffee-script, but I don't think that matters so much in this case.

@paulbjensen
Copy link
Contributor

Here is a gist I use at work. It boots a selenium server (just once), and will shut the selenium server down once the cucumber.js features have finished running: https://gist.github.com/paulbjensen/5611416.

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants