Module: Mackarel::Capybara
- Included in:
- Mackarel
- Defined in:
- lib/mackarel/capybara.rb,
lib/mackarel/capybara/form.rb
Instance Method Summary collapse
- #alt_str(alt) ⇒ Object
- #fill_autocomplete(field = "input[data-autocomplete]", options) ⇒ Object
- #fill_the_form_with(attributes) ⇒ Object
- #i_am_taken_to(path) ⇒ Object (also: #i_am_taken_to_the, #and_i_am_taken_to, #and_i_am_taken_to_the)
- #i_can_see(something) ⇒ Object (also: #and_i_can_see)
- #i_cannot_see(something) ⇒ Object
- #i_find(selector, opts = {}) ⇒ Object (also: #and_i_find, #i_find_a, #i_find_an, #and_i_find_an, #and_i_find_a)
- #i_find_no(selector, opts = {}) ⇒ Object (also: #and_i_find_no, #i_dont_find_a, #i_dont_find_an, #and_i_dont_find_an, #and_i_dont_find_a)
- #image_filters(src, alt) ⇒ Object
- #image_path(src, alt) ⇒ Object
- #select_on_form(field_name, value) ⇒ Object
- #src_str(src) ⇒ Object
- #submit_the_form(selector = "") ⇒ Object
Instance Method Details
#alt_str(alt) ⇒ Object
63 64 65 |
# File 'lib/mackarel/capybara.rb', line 63 def alt_str(alt) "@alt='#{alt}'" if alt end |
#fill_autocomplete(field = "input[data-autocomplete]", options) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/mackarel/capybara/form.rb', line 11 def fill_autocomplete(field="input[data-autocomplete]", ) fill_in field, with: .delete(:with) page.execute_script %Q{ $('#{field}').trigger("focus") } page.execute_script %Q{ $('#{field}').trigger("keydown") } sleep 1 page.execute_script %Q{ $('.ui-menu-item a:contains("#{with}")').trigger("mouseenter").trigger("click"); } end |
#fill_the_form_with(attributes) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/mackarel/capybara/form.rb', line 3 def fill_the_form_with(attributes) attributes.each do |field_name, value| field = page.find_field(field_name) next if field.set(value) select_on_form(field_name, value) end end |
#i_am_taken_to(path) ⇒ Object Also known as: i_am_taken_to_the, and_i_am_taken_to, and_i_am_taken_to_the
5 6 7 |
# File 'lib/mackarel/capybara.rb', line 5 def i_am_taken_to(path) expect(page).to have_current_path(path) end |
#i_can_see(something) ⇒ Object Also known as: and_i_can_see
9 10 11 |
# File 'lib/mackarel/capybara.rb', line 9 def i_can_see(something) expect(page).to have_content(something) end |
#i_cannot_see(something) ⇒ Object
13 14 15 |
# File 'lib/mackarel/capybara.rb', line 13 def i_cannot_see(something) expect(page).not_to have_content(something) end |
#i_find(selector, opts = {}) ⇒ Object Also known as: and_i_find, i_find_a, i_find_an, and_i_find_an, and_i_find_a
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mackarel/capybara.rb', line 17 def i_find(selector, opts={}) text = opts.delete(:with_text) case selector when String expect(page).to have_selector selector, text: text when :link pointing_to = opts.delete(:pointing_to) if pointing_to.nil? expect(page).to have_link text else expect(page).to have_link text, href: pointing_to end when :image src = opts.delete(:with_src) expect(page).to have_xpath(image_path(src, text)) end end |
#i_find_no(selector, opts = {}) ⇒ Object Also known as: and_i_find_no, i_dont_find_a, i_dont_find_an, and_i_dont_find_an, and_i_dont_find_a
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mackarel/capybara.rb', line 35 def i_find_no(selector, opts={}) text = opts.delete(:with_text) case selector when String expect(page).to have_no_selector selector, text: text when :link pointing_to = opts.delete(:pointing_to) if pointing_to.nil? expect(page).to have_no_link text else expect(page).to have_no_link text, href: pointing_to end when :image src = opts.delete(:with_src) expect(page).to have_no_xpath(image_path(src, text)) end end |
#image_filters(src, alt) ⇒ Object
57 58 59 60 61 |
# File 'lib/mackarel/capybara.rb', line 57 def image_filters(src, alt) guts = [alt_str(alt), src_str(src)].compact guts = guts.join(" and ") guts.empty? ? "" : "[#{guts}]" end |
#image_path(src, alt) ⇒ Object
53 54 55 |
# File 'lib/mackarel/capybara.rb', line 53 def image_path(src, alt) "//img#{image_filters(src, alt)}" end |
#select_on_form(field_name, value) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/mackarel/capybara/form.rb', line 19 def select_on_form(field_name, value) field = page.find_field(field_name) [value].flatten.each do |single_value| field.find(:option, single_value).select_option end end |
#src_str(src) ⇒ Object
67 68 69 |
# File 'lib/mackarel/capybara.rb', line 67 def src_str(src) "contains(@src, '#{src}')" if src end |
#submit_the_form(selector = "") ⇒ Object
26 27 28 |
# File 'lib/mackarel/capybara/form.rb', line 26 def submit_the_form(selector="") page.find("form#{selector}").find(:button).click end |