Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use "And" in a Gherkin using cucumber.js

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)

like image 914
Jackie Avatar asked Oct 24 '25 00:10

Jackie


1 Answers

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

like image 67
Jackie Avatar answered Oct 27 '25 04:10

Jackie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!