所以我在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/