Added multiple select for rack-test driver
This commit is contained in:
parent
9a91b98f8d
commit
290420191a
|
@ -32,7 +32,10 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
|
|||
end
|
||||
|
||||
def select(option)
|
||||
node.xpath(".//option[@selected]").each { |node| node.remove_attribute("selected") }
|
||||
if node['multiple'] != 'multiple'
|
||||
node.xpath(".//option[@selected]").each { |node| node.remove_attribute("selected") }
|
||||
end
|
||||
|
||||
if option_node = node.xpath(".//option[text()='#{option}']").first ||
|
||||
node.xpath(".//option[contains(.,'#{option}')]").first
|
||||
option_node["selected"] = 'selected'
|
||||
|
@ -86,9 +89,16 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
|
|||
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
|
||||
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
|
||||
node.xpath(".//input[@type='file']").map do |input|
|
||||
unless input['value'].to_s.empty?
|
||||
|
|
|
@ -33,5 +33,20 @@ shared_examples_for "select" do
|
|||
running { @session.select('Does not Exist', :from => 'form_locale') }.should raise_error(Capybara::OptionNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
context "with multiple select" do
|
||||
it "should select one option" do
|
||||
@session.select("Ruby", :from => 'Language')
|
||||
@session.click_button('awesome')
|
||||
extract_results(@session)['languages'].should == ['Ruby']
|
||||
end
|
||||
|
||||
it "should select multiple options" do
|
||||
@session.select("Ruby", :from => 'Language')
|
||||
@session.select("Javascript", :from => 'Language')
|
||||
@session.click_button('awesome')
|
||||
extract_results(@session)['languages'].should include('Ruby', 'Javascript')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -120,6 +120,16 @@
|
|||
<label for="form_pets_hamster">Hamster</label>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="form_languages">Languages</label>
|
||||
<select name="form[languages][]" id="form_languages" multiple="multiple">
|
||||
<option>Ruby</option>
|
||||
<option>SQL</option>
|
||||
<option>HTML</option>
|
||||
<option>Javascript</option>
|
||||
</select>
|
||||
</p>
|
||||
|
||||
<div style="display:none;">
|
||||
<label for="form_first_name_hidden">
|
||||
Super Secret
|
||||
|
|
Loading…
Reference in New Issue