Search code examples
node.jsselenium-webdriverautomationbddcucumberjs

Hooks in cucumberJs


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 !


Solution

  • 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.