黄瓜前一步
Cucumber 中是否有与 AfterStep 等效的 BeforeStep?
如果没有 - 有没有人找到解决方案/解决方法?
Is there a BeforeStep equivalent to AfterStep in Cucumber?
If not - has anyone found a solution / workaround?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据 GitHub 上 Cucumber Wiki 上有关 Hooks 的文档,答案是否定的。有
Before
但没有BeforeStep
。根据您想要实现的目标,Before
可能会满足您的需要。According to the documentation on Hooks on the Cucumber Wiki on GitHub, the answer is no. There is
Before
but noBeforeStep
. Depending on what you are trying to achieve,Before
might do what you need.到目前为止,
Before
在每个场景之前执行,而AfterStep
- 在场景中的每个步骤之后执行,要实现 BeforeStep,您只需将代码放在两个场景中即可挂钩:Before 和 AfterStep。So far as
Before
is executed before each scenario andAfterStep
- after each step in scenario, to achieve BeforeStep you can simply place you code in both hooks: Before and AfterStep.我知道这是一个相当过时的问题,但是:
Before 可能会明确使用,例如在场景之前,但有时它是有意义的,因为它会污染场景描述。
我在 support/hooks.rb 中使用,例如
如果必须在测试集中的每个场景之前重复某些操作,这可能会很有用
I know it is quite outdated question but:
Before might be used explicitly e.g before scenario but sometimes it is pointles due to fact that it pollute scenarios description.
I use in support/hooks.rb e.g
It might be usefull in case when some action action must be repeted before EVERY scenario in test set.
我在 TestNG 中运行黄瓜。我想在处理特征文件时打印步骤定义名称。在 TestNG 下运行时似乎不会发生这种情况。如果我在方法上有 BeforeStep 注释,例如 beforeStep(StepDefinition sd)
(或类似的东西),我会记录步骤定义名称。这将非常有用。
有没有其他方法可以用 Java Cucumber 来做到这一点?
I am running cucumber within TestNG. I'd like to print the step definition names out as the feature file is processed. This doesn't appear to happen when running under TestNG. If I had a BeforesStep annotation on a method such as beforeStep(StepDefinition sd)
(or something like that), I'd log the step definition name. That would ve very useful.
Is there a different way to do this with Java Cucumber ?