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, #native

Instance Method Summary collapse

Methods inherited from Node

#[], #click, #find, #path, #select_option, #set, #tag_name, #text, #unselect_option, #value, #visible?

Methods inherited from Node

#[], #click, #drag_to, #initialize, #inspect, #path, #select_option, #set, #tag_name, #text, #trigger, #unselect_option, #value, #visible?

Constructor Details

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

Instance Method Details

#multipart?Boolean

Returns:

  • (Boolean)


162
163
164
# File 'lib/capybara/driver/rack_test_driver.rb', line 162

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

#params(button) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/capybara/driver/rack_test_driver.rb', line 119

def params(button)
  params = {}

  native.xpath(".//input[not(@type) or (@type!='radio' and @type!='checkbox' and @type!='submit' and @type!='image')]").map do |input|
    merge_param!(params, input['name'].to_s, input['value'].to_s)
  end
  native.xpath(".//textarea").map do |textarea|
    merge_param!(params, textarea['name'].to_s, textarea.text.to_s)
  end
  native.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
  native.xpath(".//select").map do |select|
    if select['multiple'] == 'multiple'
      options = select.xpath(".//option[@selected]")
      options.each do |option|
        merge_param!(params, select['name'].to_s, (option['value'] || option.text).to_s)
      end
    else
      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
  end
  native.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



158
159
160
# File 'lib/capybara/driver/rack_test_driver.rb', line 158

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