Module: Softwear::Library::Spec::CapybaraHelpers
- Defined in:
- lib/softwear/library/spec.rb
Instance Method Summary collapse
- #accept_alert ⇒ Object
- #column_text(num) ⇒ Object
- #dismiss_alert ⇒ Object
- #eventually_fill_in(field, options = {}) ⇒ Object
- #find_label(text) ⇒ Object
- #find_label_by_text(text, options = {}) ⇒ Object
- #finished_all_ajax_requests? ⇒ Boolean
- #wait_for_ajax ⇒ Object
- #wait_for_jquery ⇒ Object
- #wait_for_redirect ⇒ Object
- #within_row(num, &block) ⇒ Object
Instance Method Details
#accept_alert ⇒ Object
36 37 38 39 |
# File 'lib/softwear/library/spec.rb', line 36 def accept_alert page.evaluate_script('window.confirm = function() { return true; }') yield end |
#column_text(num) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/softwear/library/spec.rb', line 61 def column_text(num) if RSpec.current_example.[:js] find("td:nth-child(#{num})").text else all('td')[num-1].text end end |
#dismiss_alert ⇒ Object
41 42 43 44 45 46 |
# 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 = {}) ⇒ Object
48 49 50 51 |
# File 'lib/softwear/library/spec.rb', line 48 def eventually_fill_in(field, ={}) page.should have_css('#' + field) fill_in field, end |
#find_label(text) ⇒ Object
79 80 81 |
# 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 = {}) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/softwear/library/spec.rb', line 69 def find_label_by_text(text, = {}) label = find_label(text) if ![:try] && label.nil? raise "Could not find label by text #{text}" end label end |
#finished_all_ajax_requests? ⇒ Boolean
19 20 21 |
# File 'lib/softwear/library/spec.rb', line 19 def finished_all_ajax_requests? page.evaluate_script('jQuery.active').zero? end |
#wait_for_ajax ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# 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 ⇒ Object
30 31 32 33 34 |
# 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 ⇒ Object
23 24 25 26 27 28 |
# 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) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/softwear/library/spec.rb', line 53 def within_row(num, &block) if RSpec.current_example.[:js] within("table.index tbody tr:nth-child(#{num})", &block) else within(:xpath, all('table.index tbody tr')[num-1].path, &block) end end |