如何在Cucumber的参数类型中设置布尔值?

如何在Cucumber的参数类型中设置布尔值?,cucumber,cucumberjs,Cucumber,Cucumberjs,Cucumber允许您将int、string和float作为参数类型传递,有没有一种方法可以使用boolean来实现 Given('the property {string} is set to {string}', function (path, value) { this.requestBody = this.requestBody || {}; _.set(this.requestBody, path, value); }); 简短的回答,没有,但我相信你会找到你需要的

Cucumber允许您将int、string和float作为参数类型传递,有没有一种方法可以使用boolean来实现

Given('the property {string} is set to {string}', function (path, value) {
    this.requestBody = this.requestBody || {};
    _.set(this.requestBody, path, value);
});

简短的回答,没有,但我相信你会找到你需要的

实现这一点有多种方法,大多数方法都需要在给定步骤中将值解析为布尔值。我相信你的情况就是


祝你好运

您可以通过定义for boolean巧妙地做到这一点,这将允许您在步骤表达式中使用{boolean},方法与{string}、{float}等相同

步骤定义文件

const { defineParameterType, Given } = require("@cucumber/cucumber");

defineParameterType({
  name: "boolean",
  regexp: /true|false/,
  transformer: (s) => s === "true" ? true : false
});

Given("the property {string} is set to {boolean}", function (path, value) {
  console.log(typeof value); // "boolean"
});
特征文件

Given the property "theProp" is set to true