【发布时间】: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