Cucumber, capybara, and checking for the existence of selected options within a select box
Stamped: 21 Oct 2010 | Show comments
Checking for a selected option within Cucumber/Capaybara is quite simple:
Then "hello" should be selected for "article_category_id"
And the step definition:
Then /^"([^"]*)" should be selected for "([^"]*)"$/ do |value, field|
assert page.has_xpath?("//option[@selected = 'selected' and contains(string(), '#{value}')]")
end
You could easily extrapolate this for use within an unselected value, just by removing the selected bit:
Then /^"([^"]*)" should be seen within "([^"]*)"$/ do |value, field|
assert page.has_xpath?("//option[contains(string(), '#{value}')]")
end