2

我可以使用 Cucumber Preprocessor 在 Cypress 中为相同的方法定义不同的步骤吗?

我想执行相同的操作,但步骤定义本身应该不同。有没有办法做到这一点?

4

2 回答 2

0

假设您将 Cypress 与cypress-cucumber-preprocessor一起使用,并且您的目标是为不同的步骤定义执行相同的操作,因为从业务角度来看这可能更有意义,那么一种可能的解决方案如下:

import { defineStep } from 'cypress-cucumber-preprocessor/steps';

defineStep('this is the first step with some param {string}', (param: string) => {
  doSomething(param);
});

defineStep('this is another step also with some param {string}', (param: string) => {
  doSomething(param);
});

function doSomething(param: string) {
  // do anything you like for both step definitions
}

于 2022-01-04T12:58:04.690 回答
0

您可以查看Cypress.io/Cucumber 的答案 - Given/When/Thens 的相同功能

我们在函数中使用正则表达式功能来匹配不同的步骤定义。

defineStep(/this is.*with some param "string"/, (param: string) => {
  doSomething(param);
});
于 2022-01-05T14:32:06.543 回答