所以我在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正如您所看到的,除了上传后的字符串之外,then几乎是相同的。所以我写了一个my then是这样的:
this.Then(/^that the user uploads [a-zA-Z]+/, ( option ) => {
console.log( option );
} );但选项显示function: finish。如何获取上传单词后的字符串?
发布于 2018-11-07 23:27:40
你不再需要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的道路,你真的不再需要了。
发布于 2017-05-05 15:47:08
为什么不试着这样做呢:
this.Then(/^that the user uploads an? (valid|invalid) (\w+) file/, (validity, filetype) => {
if (validity == "valid"){
console.log("this " + filetype + " is valid");
} else {
console.log("this " + filetype + " is invalid");
}
return true;
} );细目:
an? -捕获a或an (对于语法上的an?,?使n成为可选项-捕获单词无效,而valid(\w+) -捕获任何字符a-z、A-Z、0-9这意味着您可以在if语句中根据文件和文件类型的有效性执行操作。
或者,使用switch语句也可以。
this.Then(/^that the user uploads an? (valid|invalid) (\w+) file/, (validity, filetype) => {
switch(filetype){
case "pcf":
if (validity == "valid"){
// Do the stuff for valid
} else {
// Do the stuff for invalid
}
break;
default:
throw new Error("Filetype: '" + filetype + "' is not recognised");
}
return true;
});https://stackoverflow.com/questions/43740503
复制相似问题