module Softwear::Library::Spec::CapybaraHelpers
Public Instance Methods
accept_alert() { || ... }
click to toggle source
# File lib/softwear/library/spec.rb, line 36 def accept_alert page.evaluate_script('window.confirm = function() { return true; }') yield end
column_text(num)
click to toggle source
# File lib/softwear/library/spec.rb, line 61 def column_text(num) if RSpec.current_example.metadata[:js] find("td:nth-child(#{num})").text else all('td')[num-1].text end end
dismiss_alert() { || ... }
click to toggle source
# File lib/softwear/library/spec.rb, line 41 def dismiss_alert page.evaluate_script('window.confirm = function() { return false; }') yield # Restore existing default page.evaluate_script('window.confirm = function() { return true; }') end
eventually_fill_in(field, options={})
click to toggle source
# File lib/softwear/library/spec.rb, line 48 def eventually_fill_in(field, options={}) page.should have_css('#' + field) fill_in field, options end
find_label(text)
click to toggle source
# File lib/softwear/library/spec.rb, line 79 def find_label(text) first(:xpath, "//label[text()[contains(.,'#{text}')]]") end
find_label_by_text(text, options = {})
click to toggle source
# File lib/softwear/library/spec.rb, line 69 def find_label_by_text(text, options = {}) label = find_label(text) if !options[:try] && label.nil? raise "Could not find label by text #{text}" end label end
finished_all_ajax_requests?()
click to toggle source
# File lib/softwear/library/spec.rb, line 19 def finished_all_ajax_requests? page.evaluate_script('jQuery.active').zero? end
wait_for_ajax()
click to toggle source
# File lib/softwear/library/spec.rb, line 8 def wait_for_ajax begin Timeout.timeout(Capybara.default_wait_time) do wait_for_jquery loop until finished_all_ajax_requests? end rescue sleep 0.1 end end
wait_for_jquery()
click to toggle source
# File lib/softwear/library/spec.rb, line 30 def wait_for_jquery until page.evaluate_script('jQuery.active') == 0 sleep(0.1) end end
wait_for_redirect()
click to toggle source
# File lib/softwear/library/spec.rb, line 23 def wait_for_redirect original_url = current_path until current_path != original_url sleep(0.1) end end
within_row(num, &block)
click to toggle source
# File lib/softwear/library/spec.rb, line 53 def within_row(num, &block) if RSpec.current_example.metadata[:js] within("table.index tbody tr:nth-child(#{num})", &block) else within(:xpath, all('table.index tbody tr')[num-1].path, &block) end end