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 web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot
Posted by Dominik Schöler to makandra dev (2012-02-23 11:09)