-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Comments
Do you mean a single around all hook or two separate before/after all hooks? Cucumber-ruby exposes two separate hooks: |
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. |
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. |
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 |
@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. |
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. |
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. |
@trevorrowe @peteclark82 I hear you guys. Opened #97 for afterAll hook support. |
I have used the code above from @aslakhellesoy, but the global is undefined for every scenario. |
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. |
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. |
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
The text was updated successfully, but these errors were encountered: