如何使用"和"在使用cucumber.js的小黄瓜

时间:2014-07-14 23:06:24

标签: node.js cucumber cucumberjs

我正在尝试使用Cucumber.JS进行自动化测试。如果我这样做......

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

但是,如果我使用

执行以下操作,则一切正常
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

我得到了

  

TypeError:Object#没有方法'And'

那么这样做的正确方法是什么(不用说你应该在什么时候使用,因为我还有其他不那么简单的场景)

1 个答案:

答案 0 :(得分:3)

我最终能够在小黄瓜中使用And并使用this.When