【问题标题】:Generic step definitions in CucumberCucumber 中的通用步骤定义
【发布时间】:2018-04-17 22:38:33
【问题描述】:

我想知道是否可以在 cucumber 中编写通用 step_definitions,以便在需要时用于 Given、When 或 Then 场景。例如:

Given the browser is started
When I navigate to my webpage
Then the element with id login is present

Given the element with id login is present
When I press the button
Then something should happen

在这种情况下,我想为 id 为 login 的元素创建一个 step_definition,它可以在 Given 和 Then 子句中使用。

使用 Javascript,我可以输入:

defineSupportCode(({ Given, Then }) => {
    Then(/^Element with id (.+) is present$/, (name) => {
        return client.expect.element("#" + name).to.be.present;    
    });
});

虽然如果我在 defineSupportCode 中提供 Given 和 Then 这似乎有效(尽管我不明白为什么),但将步骤本身指定为 Then 感觉不正确。我更愿意将其定义为通用或类似的东西。当然我可以把场景写成:

* the element with id login is present

但这也是我实际上不喜欢的东西。我在这里遗漏了什么吗?

【问题讨论】:

    标签: cucumber gherkin cucumberjs


    【解决方案1】:

    Cucumber 中的步骤是全局的。

    Cucumber 本身并不关心步骤的方法名称。它使用正则表达式匹配要执行的方法。这意味着您可以创建您正在寻找的一般步骤。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-05
      • 2022-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多