2

I want to be able to run a Background before calling my scenario that runs steps in a previous scenario. For example, I have a scenario that creates a user and call it "Create A User". I want to create a new scenario called "Reset password" that uses "Create A User" as the Background in its feature definition.

For example here is my Feature:

Feature: Reset a password
 As a user I want to be able to reset my password

  Background: 
    Given I create an account

 Scenario: I reset my password
   Given I am a new user

So I want to be able to call "I create an account" from above to run this below:

Feature: Account creation
 As a user I want to be able to create an account

Scenario: I create an account
 Given I am at my browser
 And I click Sign up
 And ...

In the Ruby version Cucumber they have the ability to call Steps from within steps which would work: https://github.com/cucumber/cucumber/wiki/Calling-Steps-from-Step-Definitions

But the JavaScript implementation of Cumcumber , they refuse to implement this and I can't for the life of me figure out why they would want to do this: https://github.com/cucumber/cucumber-js/issues/11

How do I accomplish keeping my code DRY and not duplicating scenario step code all throughout my project?

  • 4
    They don't do it because it becomes a maintenance nightmare. What can you do? Create independent methods that are called from the steps. In the step that you would call other steps, call all the methods from those steps. – Dave McNulla Aug 13 '15 at 03:56

0 Answers0