4

I am trying to use Cucumber.JS to do my automated testing. If I do the following...

var sharedSteps = module.exports = function(){
    this.World = require("../support/world.js").World;
    this.When(/^I click on the cart$/, function(next) {
      this.client.click("#cartLink", function(err, res){
      });
    });
    ...
}

Scenario: Make sure clicking on the cart works
  Given I go on the website "https://site.com/"
  When I click on the cart
  Then I should be on the cart page

Everything works, however, if I do the following using And

var sharedSteps = module.exports = function(){
    this.World = require("../support/world.js").World;
    this.And(/^I click on the cart$/, function(next) {
      this.client.click("#cartLink", function(err, res){
      });
    });
    ...
}

Scenario: Make sure clicking on the cart works
  Given I go on the website "https://site.com/"
  And I click on the cart
  Then I should be on the cart page

I get

TypeError: Object # has no method 'And'

So what is the proper way to do this (Without saying you should be using when anyway because I have other scenarios that are not so simple)

Jackie
  • 21,969
  • 32
  • 147
  • 289

1 Answers1

4

I ended up being able to use And in the Gherkin and use this.When

Jackie
  • 21,969
  • 32
  • 147
  • 289
  • 6
    `And` is only used in scenarios, not as step definition methods. Semantically it means "same keyword as in previous step"; technically it is just another step. In fact, you can use `Given()`, `When()` and `Then()` interchangeably in your step definitions, Cucumber will not enforce a match between the step keyword and the step definition function. – jbpros Jul 23 '14 at 07:30