-
-
Notifications
You must be signed in to change notification settings - Fork 148
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
To support hooks #25
Comments
Is it possible to add a BeforeFeature hook? Such that whatever I specify in BeforeFeature will run before each feature file? (Such as clearing the test database) |
@stevepkuo I don't think you shouldn be running things before feature itself, your scenario should be independent, and they should start with a clean state everytime. That's what you can use Background functionality for |
How would the hooks work ? Would they be defined in the feature files ? In the steps file ? (but then the question is, where are they placed). I'd be happy to attempt a PR but I'm not sure how we want to design this. |
I think we would probably want to design it to resemble the cucumberjs hooks: https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/hooks.md So, in step definitions. A good attempt might be to install cucumberjs and play with their functionality and then try to reflect it here. The beforeAll afterAll might be the easiest to start :-) |
It seems that the hooks are "global" in the sense that we can't restrict them to a specific feature or scenario (which is normal I think). I think it might be better to define them in their own support file or folder with a new configuration option, similar to the ste_definitions folder. |
Yeah, I think that makes sense actually. |
actually, you can have tagged hook where you restrict hooks based on scope of tags |
What is the advised if i need to have my database reset after every scenario? The scenario is independent each time, but in my case I rely on an external service that needs to be reset |
is background step not suitable for that? |
@lgandecki Although I forgot about the Background steps (thanks for remind myself!), I was trying to attach something like the beforeEach, to just wipe the api application after every Scenario. It can be done through the Background steps as well I guess, just a preference if you want to have the api wipe/refresh as a step. Do you have any opinion about this? Does CCP support Contexts BTW? |
Could we support adding those kind of hooks inside the .feature files? It would be really helpful controlling what you want to run and when, so you don't repeat unnecessarily a large amount of code when you have a chain of actions that reuses a certain feature. Inside step_definitions or hooks folder we could have the implementation. |
@lgandecki Hi! Global hooks should available for the next reasons:
|
I am also not sure about questions whether the hooks are needed or not. The cucumber is just a DSL wrapper of actual test. In usual (mocha/chai) DSL wrapper you have
I would rather decide
vs.
@lgandecki is there any hint when it could be a reality? |
I agree with @alexttransisland that something technical has no place in the Cucumber syntax. My co-worker is trying to transform his tests to Cucumber style now. He has a login step and putting that as Is there anybody that has done some work towards this already? |
Yeah we're doing something similar as that logged in step @kayvanbree, but we've placed it in the |
I did not know background was already supported. There's no docs for it. I created #116 for that. Although I like the background section, but I would rather use it for simple feature-specific stuff, like navigating to the correct page. Seeding/resetting the database just doesn't belong in a feature file. |
@leksinteractive what do you mean it creates redundant repetitions? Do you want to leak state between different scenarios? Could you show me an example? @kayvanbree good catch. If you have a moment I'd appreciate a PR with the docs update. |
@lgandecki the usual way to use cucumber in other languages is
and then in cucumber feature you just execute your test or do additional setup per requirements |
@alexttransisland |
@lgandecki Of course I can do this if we talk about mocha/chai, but here we talk about Cucumber DSL. And there is no way to do this for cucumber features. (run same hooks) |
I still don't understand. Just put them in one of your step definitions files and they should work just fine :) I guess we could add a configurable file (like env.js) that would be imported automatically before all tests. |
btw, this cucumber is not fully a cucumber, it does use mocha beneath, so you can use all the mocha hooks. Your scenario becomes an it() block, and your feature is describe() block. |
@lgandecki great. It simply worked |
No problem.. Happy it worked! |
@lgandecki @alexttransisland should it be documented that you can use the mocha hooks? That might be useful for newcomers. (I created PR #117 fro the background section docs) |
I for one would love to see a small code example (or ideally proper documentation) of how we can use the cypress hooks within scenario steps and step definition files. Specifically i'm interested in hooks before/after each feature file, before/after the whole suite and a hook for after each scenario (as we already have the background section for before each scenario). Thanks! |
@leksinteractive There are no such hooks as far as I understand. So basically to use
to use beforeEach you could have same approach as ^ with background section, like
to use after or afterEach
According to @lgandecki current Cucumber preprocessor implementation is just a DSL which translates
meaning there should be additional codebase which supports Though my example supports any actions before/after particular |
@kayvanbree yeah, I'm happy to extend the documentation. I'm a bit worried of duplicating information from either cucumberjs OR cypress - especially if they own the API. But I think this information is so basic that it's ok to have it here. If you would like to make another PR, or you @alexttransisland - you have a good intro here, that would be great. |
@lgandecki I used the background section (added to readme) and not the hooks, so maybe @alexttransisland is better for the job. About the redundant documentation: The best part of Cypress is that you can find anything about it in one place. You don't have to look up parts in your assertion libraries docs, and some in your test runners docs. The beforeEach and afterEach (after hooks should be avoided) are explained in Cypress' documentation, but I think people would expect hooks to be a supported feature of this plugin, but instead they need to use the standard Cypress way. If we don't document that, it might be confusing. |
Hi @lgandecki To make things clear, I have made few observations regarding the support for hooks. Here is my directory structure:
Here are the observations:
Missing functionality for hooks:
|
@darasandeep91 Make sure you have Also be sure to remove |
I am facing same issue as @darasandeep91 . Hooks are seem to be always global irrespective of any folder they are placed. @sanik-bajracharya I did the settings mentioned still hooks are global. Scenario which are affected due to this in my case is: @lgandecki is there any way to make hooks non-global so that they are feature file specific (as this is something much need than global hooks ) which I might be missing how to do or we don't have support for this in Cypress yet? Thanks in advance! |
@ReemaMoroney @sanik-bajracharya this is exactly how it should be, and works, as in the example here: https://github.com/TheBrainFamily/cypress-cucumber-example . Please make a reproduction if it doesn't work for you. There is one caveat which is running all features inside the GUI at the same time - cypress-io/cypress#3323 which is a bug in cypress. But if you run your tests with run or separately, the hooks should not be global. |
feat: Added cucumber-js-style Before and After hooks. Related: #25
🎉 This issue has been resolved in version 1.14.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
hooks are not supported feature yet
The text was updated successfully, but these errors were encountered: