Class: Capybara::Driver::RackTest::Form

Inherits:
Node
  • Object
show all
Defined in:
lib/capybara/driver/rack_test_driver.rb

Instance Attribute Summary

Attributes inherited from Node

#driver, #node

Instance Method Summary collapse

Methods inherited from Node

#[], #click, #path, #select, #set, #tag_name, #text, #visible?

Methods inherited from Node

#[], #click, #drag_to, #initialize, #path, #select, #set, #tag_name, #text, #value, #visible?

Methods included from Searchable

#all, #find, #find_button, #find_by_id, #find_field, #find_link

Constructor Details

This class inherits a constructor from Capybara::Node

Instance Method Details

#multipart?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/capybara/driver/rack_test_driver.rb', line 106

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

#params(button) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/capybara/driver/rack_test_driver.rb', line 71

def params(button)
  params = {}
  node.xpath(".//input[@type='text' or @type='hidden' or @type='password']").map do |input|
    merge_param!(params, input['name'].to_s, input['value'].to_s)
  end
  node.xpath(".//textarea").map do |textarea|
    merge_param!(params, textarea['name'].to_s, textarea.text.to_s)
  end
  node.xpath(".//input[@type='radio' or @type='checkbox']").map do |input|
    merge_param!(params, input['name'].to_s, input['value'].to_s) if input['checked']
  end
  node.xpath(".//select").map do |select|
    option = select.xpath(".//option[@selected]").first
    option ||= select.xpath('.//option').first
    merge_param!(params, select['name'].to_s, (option['value'] || option.text).to_s) if option
  end
  node.xpath(".//input[@type='file']").map do |input|
    unless input['value'].to_s.empty?
      if multipart?
        content_type = MIME::Types.type_for(input['value'].to_s).first.to_s
        file = Rack::Test::UploadedFile.new(input['value'].to_s, content_type)
        merge_param!(params, input['name'].to_s, file)
      else
        merge_param!(params, input['name'].to_s, File.basename(input['value'].to_s))
      end
    end
  end
  merge_param!(params, button[:name], button[:value]) if button[:name]
  params
end

#submit(button) ⇒ Object



102
103
104
# File 'lib/capybara/driver/rack_test_driver.rb', line 102

def submit(button)
  driver.submit(method, node['action'].to_s, params(button))
end