Class: Capybara::RackTest::Form

Inherits:
Node show all
Defined in:
lib/capybara/rack_test/form.rb

Defined Under Namespace

Classes: NilUploadedFile, ParamsHash

Instance Attribute Summary

Attributes inherited from Driver::Node

#driver, #native

Instance Method Summary collapse

Methods inherited from Node

#==, #[], #all_text, #checked?, #click, #disabled?, #find_css, #find_xpath, #path, #select_option, #selected?, #set, #tag_name, #unselect_option, #value, #visible?, #visible_text

Methods inherited from Driver::Node

#==, #[], #all_text, #checked?, #click, #disabled?, #double_click, #drag_to, #hover, #initialize, #inspect, #multiple?, #path, #readonly?, #right_click, #select_option, #selected?, #send_keys, #set, #tag_name, #trigger, #unselect_option, #value, #visible?, #visible_text

Constructor Details

This class inherits a constructor from Capybara::Driver::Node

Instance Method Details

#multipart?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/capybara/rack_test/form.rb', line 52

def multipart?
  self[:enctype] == "multipart/form-data"
end

#params(button) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/capybara/rack_test/form.rb', line 21

def params(button)
  params = make_params

  form_element_types = %i[input select textarea]
  form_elements_xpath = XPath.generate do |x|
    xpath = x.descendant(*form_element_types).where(~x.attr(:form))
    xpath = xpath.union(x.anywhere(*form_element_types).where(x.attr(:form) == native[:id])) if native[:id]
    xpath.where(~x.attr(:disabled))
  end.to_s

  native.xpath(form_elements_xpath).map do |field|
    case field.name
    when 'input'
      add_input_param(field, params)
    when 'select'
      add_select_param(field, params)
    when 'textarea'
      add_textarea_param(field, params)
    end
  end
  merge_param!(params, button[:name], button[:value] || "") if button[:name]

  params.to_params_hash
end

#submit(button) ⇒ Object



46
47
48
49
50
# File 'lib/capybara/rack_test/form.rb', line 46

def submit(button)
  action = (button && button['formaction']) || native['action']
  method = (button && button['formmethod']) || request_method
  driver.submit(method, action.to_s, params(button))
end