如何在 Ruby Cucumber 的主要步骤中使用另一个步骤?
我有一个名为“ForPreEdit.rb”的step_definition,当我想运行这个单独的步骤时,其标签是@preed(效果很好)。 我还有名为“LoginSolic.rb”的step_definition,其标签是@loginSolicitante(也可以完美运行)。 在step_definition“ForPreEdit”的“When .... End”内部,我需要运行step_definition“LoginSolic”才能登录。我为此使用以下语法: “步骤 %Q { 当我想以请求者身份登录时 }"
执行时,没有报错,只是代码被忽略了。我的Gemfile Cucumber版本是5.2。更多代码细节如下:
09 When('I perform my Login as Requester:') do |table|
10 # LOGIN
11 steps %Q{
12 When I want to Login as Requester
13 }
14 find('#Country').find(:xpath, 'option[5]').select_option
15 sleep 5
16 find('#DocumentType').find(:xpath, 'option[2]').select_option
第11、12、13行被忽略,程序从第14行开始执行,并在线14 发生错误,因为它取决于第 12 行的执行。同样,当单独运行时,两者都可以完美工作。
I have the step_definition called "ForPreEdit.rb", whose tag is @preed when I want to run this separate step (which works perfectly).
I also have the step_definition called "LoginSolic.rb", whose tag is @loginSolicitante (also works perfectly).
Inside "When .... End" of step_definition "ForPreEdit" I need to run step_definition "LoginSolic" to login. I'm using the following syntax for this:
"steps %Q {
When I want to Login as Requester
}"
When executing, no error is reported, simply the code is being ignored. My version of Gemfile Cucumber is 5.2. More code details below:
09 When('I perform my Login as Requester:') do |table|
10 # LOGIN
11 steps %Q{
12 When I want to Login as Requester
13 }
14 find('#Country').find(:xpath, 'option[5]').select_option
15 sleep 5
16 find('#DocumentType').find(:xpath, 'option[2]').select_option
Lines 11, 12 and 13 are ignored, the program starts executing from line 14, and on line 14 an error occurs because it depends on the execution of line 12. Again, when running separately, both work perfectly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,嵌套步骤是一种反模式,应该避免。当您使用 ruby 时,您应该理想地执行以下所有步骤。
嵌套 示例
将任何嵌套提取到辅助方法中总是更加干净和简单方法,如果您确保所有步骤定义默认实现为对辅助方法的调用,那么它会特别容易。随着你的杯子套件的增加,避免阶梯嵌套所带来的好处也会成倍增加。
这里有一组功能和步骤更深入地说明了这个概念 https://github .com/diabolo/cuke_up/tree/master/features。我想通过学习它们你会收获很多。
In general nesting steps is an anti-patten and should be avoided. As you are using ruby you should do the following ideally with all your steps.
An example
It is always much cleaner and simpler to extract any nesting into a helper method, and its particularly easy if you ensure all your step definitions are implemented by default as calls to helper methods. As your suite of cukes grows the benefits you get from avoiding nesting in steps multiply.
There are a set of features and steps illustrating this concept in more depth here https://github.com/diabolo/cuke_up/tree/master/features. I think you will gain alot by studying them.