黄瓜 JS - 选择句子的一部分或全部



我正在尝试定义一个可重用的步骤,其中包含相同的逻辑,但措辞可能不同。例如:

the message "Running defect detection module..." should be displayed

the message "Defect detection complete." should be displayed when the process is complete

到目前为止,我的正则表达式如下所示:

/^the message "([^"]*)" should be displayed$/

我也尝试做以下正则表达式:

/^the message "([^"]*)" should be displayed(s*w*)*$/

但我没有得到任何结果。有什么想法吗?

提前谢谢你

这个呢?

function check(str) {
return /^the message "(.*)" should be displayed(.*)$/.test(str);
}
function test(str) {
console.log(str, " => ", check(str));
}
test("the message "Running defect detection module..." should be displayed");
test("the message "Defect detection complete." should be displayed when the process is complete");

我建议不要尝试创建这样的步骤。而是给消息一个名称(它封装了它试图传达的内容(,并为每个消息编写一个步骤

。例如

然后"我应该看到缺陷检测正在运行" 然后"我应该看到缺陷检测完成">

黄瓜不适合精确测试UI中显示的内容。这个想法是使用UI中显示的内容来确认某个业务行为是否有效,并且这样做的方式是,每次更改一个小细节时,场景都不会失败(例如,消息以大写字母开头,或者添加了一些标点符号,或者您使用一些很酷的图形来显示缺陷检测正在运行(。

使用正则表达式创建复杂的步骤以匹配一系列场景内容是一种反模式。大约 10 年前,当我开始嘘寒问暖时,我在每一步定义中使用正则表达式,现在我根本不使用它们。

最新更新