Read more

Issues with has_select?

Dominik Schöler
February 23, 2012Software engineer at makandra GmbH

The handy method has_select?(field, :selected => text) does not behave as expected with Cucumber 0.10.2, Capybara 0.4.1.2 and Selenium 0.2.2. It may not recognize a select field if the selected option with the text has no value. If you don't have the possibility to upgrade these Gems, probably the best way to go is to distinguish the current Capybara driver:

Then /^"([^"]*)" should be selected for "([^"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector|
  with_scope(selector) do

    # currently needed due to different behaviour of Capybara drivers
    if page.driver.class.name == "Capybara::Driver::RackTest"
      xpath_field = find_field(field)
      selected_option = xpath_field.find(:xpath, "option[@selected='selected']") rescue nil
      selected_option ||= xpath_field.find(:xpath, 'option')
      selected_option.text.should == value      
    else      
      page.should have_select(field, :selected => value)
    end
  end
end
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot
Posted by Dominik Schöler to makandra dev (2012-02-23 11:09)