1

I am using cucumberJS with Request package to test my web APIs. In cucumberJS I want to use different kind of hooks. Reference - Here I see only Before and After hooks. Specifically I look for a hook to handle actions before my test execution starts (simillar to onPrepare - in protractor). Please help me !

Thanks in advance !

1 Answer 1

2

I think you are looking for event handlers. With the event handler you can prepare your environment before:

  • all features
  • a feature
  • a scenario
  • a step

I'm also wondering what you exactly want to do with the preparation, because the onPrepare in protractor is only a thing that can handle methods when the browser is already active, but the tests are not executed.

If you want to prepare you environment before all tests start you can or have a different (npm) script that will do this for you before the cucumber script is run, or when you use protractor, use a beforeLaunch function.

3
  • I wanted to assign few global variables like global.expect = chai.expect; global.environment = appConfig.t1b; before my test starts. Thanks !!! Jul 4, 2017 at 18:31
  • You are welcome, did it also help? And if so, can you share your solution in your question so everybody can learn from it? Jul 4, 2017 at 18:33
  • Live example: testjam.io/?p=6s0O9gKZfWl4odC8h5t2 Jul 9, 2022 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.