我想确保以下测试不会陷入无限循环。我想让循环运行一定次数。
When /^I click the Settings link$/ do
footer = @browser.div(:id, 'iwinbottombar')
footer.wait_until_present
unless footer.html.include?('Settings')
throw Exception.new("Expected to see the settings button but it was not there")
end
until @browser.div(:id, 'dialogcontainer').div(:class, 'settings_browsebutton button clickable').present? do
footer.a(:class, 'button_settings').when_present.click
end
end
但我不确定如何限制代码来做到这一点。我想我需要一个计数器,但我不确定如何实现它。
答案 0 :(得分:2)
如果我找到了你,你需要while
/ until
之类的东西,但最多重试次数:
10.times do
break if condition_met?
do_whatever
end