Cucumber允许您将int,string,floats作为参数类型传递,有没有办法使用布尔值呢?
Given('the property {string} is set to {string}', function (path, value) {
this.requestBody = this.requestBody || {};
_.set(this.requestBody, path, value);
});
答案 0 :(得分:1)
答案 1 :(得分:0)
您可以通过为布尔值定义一个 custom parameter type 来巧妙地做到这一点,这将允许您以与 {string}、{float} 等相同的方式在步骤表达式中使用 {boolean}。
步骤定义文件
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