lib/kelp/dropdown.rb
# Verify that the selected option in a dropdown has the given
# value. Note that this is the *visible* content of the dropdown
# (the content of the <option> element), rather than the
# 'value' attribute of the option.
#
# @param [String] dropdown
#   Capybara locator for the dropdown (the `select` element)
# @param [String] value
#   Value you expect to see as the currently-selected option
# @param [Hash] scope
#   Scoping keywords as understood by {#in_scope}
#
# @raise [Kelp::Unexpected]
#   If the given dropdown does not equal `value`
#
Verify that the selected option in a dropdown has the given
value. Note that this is the *visible* content of the dropdown
(the content of the  element), rather than the
'value' attribute of the option.
Verify that the selected option in a dropdown has the given value . Note that this is the * visible * content of the dropdown ( the content of the element ) rather than the ' value ' attribute of the option .
def dropdown_should_equal(dropdown, value, scope={})
      in_scope(scope) do
        field = nice_find_field(dropdown)
        begin
          selected = field.find(:xpath, ".//option[@selected='selected']")
        rescue Capybara::ElementNotFound
          if field.value.class == Array
            raise NotImplementedError, "Multiple-selection dropdowns are not supported"
          end
          field_value = xpath_sanitize(field.value)
          selected = field.find(:xpath, ".//option[@value=#{field_value}]")
        end
        if selected.text != value
          raise Kelp::Unexpected,
            "Expected '#{dropdown}' dropdown to equal '#{value}'\nGot '#{selected.text}' instead"
        end
      end
    end
def dropdown_should_equal ( dropdown , value , scope = { } ) in_scope ( scope ) do field = nice_find_field ( dropdown ) begin selected = field . find ( :xpath , ".//option[@selected='selected']" ) rescue Capybara :: ElementNotFound if field . value . class == Array raise NotImplementedError , "Multiple-selection dropdowns are not supported" end field_value = xpath_sanitize ( field . value ) selected = field . find ( :xpath , ".//option[@value=#{field_value}]" ) end if selected . text != value raise Kelp :: Unexpected , "Expected '#{dropdown}' dropdown to equal '#{value}'\nGot '#{selected.text}' instead" end end end
Verify that the selected option in a dropdown has the given
value.
Verify that the selected option in a dropdown has the given value .
# See if there's a 'selected' option # If not, find the option matching the field's 'value' attribute # FIXME: Find a way to support multiple-selection dropdowns
[Kelp::Unexpected] If the given dropdown does not equal `value`
[ Kelp :: Unexpected ] If the given dropdown does not equal ` value `
dropdown
<not_specific>
value
<not_specific>
scope
<not_specific>
<not_specific>
scope Scoping keywords as understood by {#in_scope}
scope Scoping keywords as understood by { #in_scope }