Sha256: 3f0829ecbb2d28050f42af7942ea5ffaff7f17b7aa65c246eb93a58e1ddbede0

Contents?: true

Size: 1.54 KB

Versions: 17

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

require ::File.expand_path("../util/configuration", File.dirname(__FILE__))
require ::File.expand_path("finder_diagnostics", File.dirname(__FILE__))

require "active_support/concern"

module Cornucopia
  module Capybara
    module SelectableValues
      extend ActiveSupport::Concern

      # select_value finds the option with the value #value then calls select_option on that item.
      #
      # select_value only works on select boxes.
      def select_value(values)
        raise "select_value is only valid for select items" unless self.tag_name == "select"

        if values.is_a?(Array)
          values.each do |value|
            html_safe_value = "".html_safe + value.to_s
            self.find("option[value=\"#{html_safe_value}\"]", visible: false).select_option
          end
        else
          html_safe_value = "".html_safe + values.to_s
          self.find("option[value=\"#{html_safe_value}\"]", visible: false).select_option
        end
      end

      # value_text returns the text for the selected items in the select box instead of the value(s)
      #
      # value_text only works on select boxes.
      def value_text
        raise "value_text is only valid for select items" unless self.tag_name == "select"

        values = self.value
        if values.is_a?(Array)
          values.map do |value|
            self.find("option[value=\"#{value}\"]", visible: false).text
          end
        else
          self.find("option[value=\"#{values}\"]", visible: false).text
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
cornucopia-0.2.0 lib/cornucopia/capybara/selectable_values.rb
cornucopia-0.1.56 lib/cornucopia/capybara/selectable_values.rb
cornucopia-0.1.55 lib/cornucopia/capybara/selectable_values.rb
cornucopia-0.1.54 lib/cornucopia/capybara/selectable_values.rb
cornucopia-0.1.53 lib/cornucopia/capybara/selectable_values.rb
cornucopia-0.1.52 lib/cornucopia/capybara/selectable_values.rb
cornucopia-0.1.51 lib/cornucopia/capybara/selectable_values.rb
cornucopia-0.1.50 lib/cornucopia/capybara/selectable_values.rb
cornucopia-0.1.49 lib/cornucopia/capybara/selectable_values.rb
cornucopia-0.1.48 lib/cornucopia/capybara/selectable_values.rb
cornucopia-0.1.47 lib/cornucopia/capybara/selectable_values.rb
cornucopia-0.1.46 lib/cornucopia/capybara/selectable_values.rb
cornucopia-0.1.45 lib/cornucopia/capybara/selectable_values.rb
cornucopia-0.1.44 lib/cornucopia/capybara/selectable_values.rb
cornucopia-0.1.43 lib/cornucopia/capybara/selectable_values.rb
cornucopia-0.1.42 lib/cornucopia/capybara/selectable_values.rb
cornucopia-0.1.41 lib/cornucopia/capybara/selectable_values.rb