regex - cucumber 正则表达式

标签 regex cucumberjs

所以我在cucumberjs中有这个功能

Scenario: Upload a valid pcf file into gpe
            Given that the user uploads a valid pcf file
            Then the user should see an upload success indicator

     Scenario: Upload an invalid pcf file
            Given that the user uploads an invalid pcf file
            Then the user should see an upload error message

如您所见,除了上传后的字符串外,它们几乎相同。所以我写了一个这样的:

this.Then(/^that the user uploads [a-zA-Z]+/, ( option ) => {
   console.log( option );
} );

但选项显示功能:完成。如何获取上传单词后的字符串?

最佳答案

您不再需要 RegEx!哇!见下文。

Scenario: Upload an "valid pcf file into gpe"
        Given that the user uploads a valid pcf file
        Then the user should see an upload success indicator

Scenario: Upload an "invalid pcf file"
            Given that the user uploads an invalid pcf file
            Then the user should see an upload error message

在您的场景中使用它,当您将文本包装在 ""中时,它现在是一个准备传递到您的 JS 中的字符串

this.Then(Upload an {string}, ( stringSwitcher ,option ) => {

这就是您开始 JS 的行的工作方式,您可以将 stringSwitcher 命名为任何您想要的名称,但这是存储场景的独特部分的内容,本质上是在场景中上传一个“blablabla”,它将能够使用用于传递它的 javascript。

我希望这是有道理的,但我已经走上了使用 regEx 的道路,你真的不需要了。

关于regex - cucumber 正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43740503/

相关文章:

javascript - Protractor - 框架中的错误处理

javascript - 黑猩猩.js 配置

python - 匹配除三个连续双引号之外的所有内容

java - 我如何升级此正则表达式不捕获 "1hey"或 "123_456_bye"或 "1123_hey"

java - Unicode 字符正则表达式,捕获组

mysql - phpmyadmin 中的日期格式正则表达式测试

javascript - 使用 Chai 解决 Protractor 和 Cucumber 中的 promise

javascript - 毕竟 Hook 错误 - 使用 cucumber-js 和 selenium 时 'this' 并未引用我的世界构造函数

javascript - 如何使用回调将 cucumber 测试标记为 Node 中的待处理

regex - Perl 中字符串之间的字符匹配计数