Search code examples
automated-testsbehat

Using another scenario from another feature in current scenario, Behat testing


So my question is can I use a bunch of steps defined in another scenario that was used in a different feature file?

eg: I have a feature file that helps create some pages on the website. Now i want a different scenario in a different feature file that will create the pages and also add some other steps to it. In this case, I want to create a page, and this triggers a notification to a particular user, and I want to work with the notifications. But cannot do so without triggering a page creation action by the user. It is just a bunch of 5 steps. but i am trying to reduce steps as much as possible to keep it simple.

Of the top of my head, maybe use tags and then use the tags to combine two scenarios. but i am not sure if we can do that

So i want to know if there is a way of code reuse in this case. And if so, HOW?

Thank you


Solution

  • You could define a new step like ‘I create a page’, and under the hood reuse the steps from other contexts as explained here: https://behat-docs.readthedocs.io/en/mvp1.0/cookbooks/gathering_contexts_when_using_multiple_contexts.html