我想在列表中添加100个名字。我使用的是Calabash,所以我有.feature文件:
When I fill the item field with "3"
And press the button Adicionar
And I repeat the previous 2 steps 100 times
我的.rb文件:
...
When(/^I repeat the previous (\d+) steps (\d+) times$/) do |steps, times|
如何实现此.rb文件?我尝试的最后一件事,我得到了错误:
Undefined dynamic step: "2" (Cucumber::UndefinedDynamicStep)
答案 0 :(得分:0)
您有一个名单列表,然后您可以使用数据表传递它,您可以按如下方式编写组合步骤:
Given I add following names in the list:
|Ram|
|Abdul|
|Scot|
然后您可以使用嵌套步骤编写步骤定义,如下所示:.rb文件:
Given(/^I add following names in the list:$/) do |table|
data = table.raw
data.each do |row|
steps %{
When I fill the item field with "#{row[0]}"
And press the button Adicionar
}
end
end
When(/^I fill the item field with "([^"]*)"$/) do |arg1|
pending # Write code to enter the the item
end
When(/^press the button Adicionar$/) do
pending # Write code to click the Adicionar button
end
如果您只想填写同名“3”的名称,那么您可以按如下方式编写合并步骤:
鉴于我用“3”100次填充项目字段
然后您可以编写以下步骤定义:
Given(/^I fill the item field with "([^"]*)" (\d+) times$/) do |name, loop_count|
loop_count.to_i.times do
steps %{
When I fill the item field with "#{name}"
And press the button Adicionar
}
end
end
When(/^I fill the item field with "([^"]*)"$/) do |arg1|
pending # Write code to enter the the item
end
When(/^press the button Adicionar$/) do
pending # Write code to click the Adicionar button
end