I am using cypress and cucumber. There is a common folder with steps that are shared. I want to create a step that consist of few other different steps is there any way how can I achieve it?

Example:

And("step1", () => {
...
})

And("step2", () => {
...
})

And("step3", () => {
...
})

And("combined", () => {
step1
step2
step3
})

Solution 1:

The best way do this is to have the step call a helper method and have the method call other helper methods. If you follow this approach you remove all the cucumber specific stuff from your problem and you allow yourself the space to customise your solution and make it more robust.

In ruby I would do this as follows

module StepHelper
  def step1
  end

  def step2
  end

  def combined
    step1
    step2
  end
end
World StepHelper

And "step 1" do
  step1
end

And "step 2" do
  step2
end

And "combined" do 
  combined
end

Note the last scenario implementation, it is much better than

And "combined" do
  step1
  step2
end

You'll need to translate this to cypress (sorry I can't help you with that)