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 BeforeStep / AfterStep hooks #281

Merged
merged 13 commits into from
Feb 17, 2025

Conversation

the3dsandwich
Copy link
Contributor

As discussed in #280

The BeforeStep and AfterStep hooks will enable code to be run before each Given, When, Then, etc. steps.

This way, we will be able to attach screenshots for every step.

@vitalets
Copy link
Owner

Let's add a test for step hooks in a new folder test/hooks-step. You can use test/hooks-order-one-feature as a reference. To run this particular test: npm run only test/hooks-step.

@the3dsandwich
Copy link
Contributor Author

Let's add a test for step hooks in a new folder test/hooks-step. You can use test/hooks-order-one-feature as a reference. To run this particular test: npm run only test/hooks-step.

I added test/hook-step, renamed use to result, and renamed getHookStepTitle to BeforeStep/AfterStep.

regarding enabling page fixture in addition to common this.bddContext, any idea how we can proceed?

@vitalets
Copy link
Owner

I've updated test/hooks-step a bit: removed scenario and worker hooks. Pushed the changes to your branch, so it's in the pr.
Now let me think a bit how to pass fixtures to the step hooks. Will post updates here.

@the3dsandwich
Copy link
Contributor Author

I found that I haven't changed StepHookType from ScenarioHookType. Renaming in this commit.

@vitalets
Copy link
Owner

Hi @the3dsandwich

I've pushed the fix for passing fixtures to step hooks, on top of your last commit.
Now we only need to write the docs about step hooks.

  • describe in the Hooks section
  • add to API section

Are you willing to contribute to the docs as well?
If yes, you can run npm run docs and check edits locally.

@the3dsandwich
Copy link
Contributor Author

Working on it. Will push something ASAP

@the3dsandwich
Copy link
Contributor Author

I wasn't aware that tagging exist, so I'm unsure whether I got that part of the documentation right. Would you mind double-checking the contents are accurate?
In terms of docsify, did you install via npm i -g docsify?

.prototools Outdated
@@ -0,0 +1,2 @@
node = "~20"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this file for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad. I should have left this file out of the commit. It's to specify that this repo uses node 20 for this tool https://moonrepo.dev/proto

@vitalets
Copy link
Owner

@the3dsandwich in your scenario with screenshots, if step fails do you expect the AfterStep still run?

the3dsandwich and others added 2 commits February 15, 2025 21:40
Co-authored-by: Vitaliy Potapov <potapov.vitaliy@gmail.com>
@the3dsandwich
Copy link
Contributor Author

I personally do not expect AfterStep to run if a step fails and throws an error. If I want a screenshot of failed tests I would add it to the playwright config, or use a fixture to edit the title or something.

@the3dsandwich
Copy link
Contributor Author

I updated the docs a bit further, so that the example of taking a screenshot after every step is in the AfterStep block.

the3dsandwich and others added 2 commits February 16, 2025 19:12
Co-authored-by: Vitaliy Potapov <potapov.vitaliy@gmail.com>
@vitalets vitalets merged commit e685d09 into vitalets:main Feb 17, 2025
@the3dsandwich the3dsandwich deleted the hook-before-after-step branch February 18, 2025 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants