-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Feature: BeforeFeature / AfterFeature hooks #219
Comments
What should be a default behavior of
What do you think? |
I vote for 1st option |
I thought more about that question. If As of now, I'm thinking about the following changes:
Example code: const { BeforeWorker } = createBdd();
BeforeWorker({ tags: '@auth', once: true }, async () => {
// heavy setup of test user in database for checking all auth stuff
}); Feature file can contain @auth
Feature: check auth
Scenario: check login Or on the scenario level: Feature: check auth
@auth
Scenario: check login If at least one scenario of feature has the matching tag, |
The problem
Sometimes we need to run code before / after particular feature file. Currently it can be achieved in playwright-bdd only with some hacks.
In CucumberJS it's not possible - there were several related requests:
CucumberJS FAQ states that these hooks are not possible, because runner does not consider features when running scenarios.
A solution
Playwright provides a direct way to run code before particular file - test.beforeAll / test.afterAll. We can just utilize that.
SpecFlow also provides BeforeFeature / AfterFeature hooks.
Binding to features can be done by tags - the same as for scenario hooks. Example code:
This also matches the proposed tags from path approach.
You can put feature files and BeforeFeature hooks into
@
-prefixed directory, and they will be bound automatically:Hooks naming
Hooks naming between Cucumber and Playwright is a bit confusing:
BeforeEach / AfterEach
= Cucumber'sBefore / After
- run before/after each scenarioBeforeAll / AfterAll
= (no alternative in CucumberJS) - run before/after each featureBeforeAll / AfterAll
- run before/after each workerI like the explicit naming in SpecFlow:
BeforeScenario / AfterScenario
BeforeFeature / AfterFeature
BeforeWorker / AfterWorker
I think, we can use these aliases in playwright-bdd.
Running once
There is a request from community to run
beforeFeature
hooks only once, even infullyParallel
mode / in case when some tests are failing and new worker is created.Keep in mind during implementation, see microsoft/playwright#22520 (comment)
I you have any thoughts / concerns here, feel free to share in comments.
Or just add your 👍
The text was updated successfully, but these errors were encountered: