Module: Helpers::Main
- Includes:
- NodeFinders, Waiter
- Defined in:
- lib/cucumber/pickles/helpers/main.rb
Instance Method Summary collapse
-
#attach_file(input, file) ⇒ Object
Attach file from features/support/attachments/* to given file input.
-
#blur(node) ⇒ Object
trigger blur event on given node.
-
#parent_node(node) ⇒ Object
parent node of given.
-
#select_input(input, value = nil) ⇒ Object
Select checkbox | radio input.
-
#trigger(node, event) ⇒ Object
Triggers event on node Usefull when Capybara raises error about element being covered by another.
Methods included from Waiter
page, pending_ajax_requests_num, wait, wait_for_ajax
Methods included from NodeFinders
#_rescued_find, #detect_node, #find_input, #find_node, #guess_node
Instance Method Details
#attach_file(input, file) ⇒ Object
Attach file from features/support/attachments/* to given file input
returns [void]
68 69 70 71 72 73 74 |
# File 'lib/cucumber/pickles/helpers/main.rb', line 68 def attach_file(input, file) path = File.(File.join(SUPPORT_DIR,"attachments/#{file}")) raise RuntimeError, "file '#{path}' does not exists" unless File.exists?(path) input.set(path) end |
#blur(node) ⇒ Object
trigger blur event on given node
25 26 27 28 29 |
# File 'lib/cucumber/pickles/helpers/main.rb', line 25 def blur(node) trigger(node, 'blur') Capybara.current_session.execute_script("document.body.click()") end |
#parent_node(node) ⇒ Object
parent node of given
returns Capybara node
16 17 18 |
# File 'lib/cucumber/pickles/helpers/main.rb', line 16 def parent_node(node) node.find(:xpath, '..', wait: 0, visible: false) end |
#select_input(input, value = nil) ⇒ Object
Select checkbox | radio input
returns: [void]
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/cucumber/pickles/helpers/main.rb', line 39 def select_input(input, value = nil) case value when "true", true value = true when "false", false value = false else value = !input.checked? end # # Hack: # cant use input.set(#{value}) # because element can be hidden or covered by other eement # in which case Selenium raises error # trigger(parent_node(input), 'click') Capybara.current_session.execute_script("arguments[0].checked = #{value}", input) end |
#trigger(node, event) ⇒ Object
Triggers event on node Usefull when Capybara raises error about element being covered by another
returns: [void]
84 85 86 |
# File 'lib/cucumber/pickles/helpers/main.rb', line 84 def trigger(node, event) Capybara.current_session.execute_script("arguments[0].#{event}()", node) end |