Test that a select option is selected with Cucumber

Updated . Posted . Visible to the public.

This step tests whether a given select option comes preselected in the HTML. There is another step to test that an option is available at all.

Capybara

Then /^"([^"]*)" should be selected for "([^"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector|
  with_scope(selector) do
    field_labeled(field).find(:xpath, ".//option[@selected = 'selected'][text() = '#{value}']").should be_present
  end
end

Webrat

Then /^"([^"]*)" should be selected for "([^"]*)"$/ do |value, field|
  field_labeled(field).element.search(".//option[@selected = 'selected']").inner_html.should =~ /#{value}/
end
Henning Koch
Last edit
Keywords
cucumber
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2010-11-19 11:23)