我想重复使用一些黄瓜步骤,但似乎找不到正确的方法。
我想写一个这样的步骤:
Given /^I login with (.*) credentials$/ |type|
# do stuff with type being one of "invalid" or "valid"
end
但还有另一个步骤,例如:
Given /^I login successfully$
# call "Given I login with valid credentials"
end
因此,在测试用户身份验证时,我可以使用前者,但在大多数其他地方,我可以使用后者,而实际上不必重新生成代码。
有没有办法调用其他步骤,或者我只是将逻辑放入辅助方法中,然后从每个任务中调用所述方法(基本上是方法提取重构,在阅读我的问题后,我相信这实际上是最好的方法反正)?
请注意,在最新版本的 Cucumber 中,在步骤中调用步骤的方法已发生更改,如果您收到类似“警告:不推荐在步骤定义中使用‘Given/When/Then’,请使用‘step’来改为调用其他步骤:/path/to/step_definitions/foo_steps.rb:631:in `block in '
”。参见黄瓜维基 https://cucumber.io/docs/guides/anti-patterns/#support-for-conjunction-steps了解详情。
更改的要点是您现在应该使用step
or steps
方法。
When /^I make all my stuff shiny$/
step "I polish my first thing"
end
When /^I make all my stuff shiny$/
steps %Q{
When I polish my first thing
When I shine my second thing
}
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)