Skip to content

Instantly share code, notes, and snippets.

@bernerdschaefer
Created May 12, 2010 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bernerdschaefer/398817 to your computer and use it in GitHub Desktop.
Save bernerdschaefer/398817 to your computer and use it in GitHub Desktop.
def wait_conditionally_until
if page.driver.wait?
page.wait_until do
begin
yield
rescue Selenium::WebDriver::Error::WebDriverError => e
# do nothing - continue to wait for timeout
end
end
else
yield
end
end
# before: this can find the field before it's been checked!
Then /^the "([^\"]*)" checkbox(?: within "([^\"]*)")? should not be checked$/ do |label, selector|
with_scope(selector) do
[true, 'checked'].should_not include(find_field(label)['checked'])
end
end
# after: so capybara now has real methods for this!
Then /^the "([^\"]*)" checkbox(?: within "([^\"]*)")? should not be checked$/ do |label, selector|
with_scope(selector) do
page.should have_unchecked_field(label)
end
end
# before: all does not implement waiting!
Then /^the "([^\"]*)" list should have (\d) items?$/ do |list, num|
all(:css, "#{list} li").count.should == num.to_i
end
# after
Then /^the "([^\"]*)" list should have (\d) items?$/ do |list, num|
wait_conditionally_until do
all(:css, "#{list} li").count == num.to_i
end.should be_true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment