Sha256: 88d62ce485cd359a9f15718a9695d99c43caaa6e1d7ea851302a2c4f1a1eecb2

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

module TestCentricity
  class Radio < UIElement

    def initialize(parent, locator, context)
      @parent  = parent
      @locator = locator
      @context = context
      @type    = :radio
      @alt_locator = nil
    end

    # Is radio button selected?
    #
    # @return [Boolean]
    # @example
    #   accept_terms_radio.selected?
    #
    def selected?
      obj, _ = find_element
      object_not_found_exception(obj, 'Radio')
      obj.checked?
    end

    # Set the select state of a radio button object.
    #
    # @param state [Boolean] true = selected / false = unselected
    # @example
    #   accept_terms_radio.set_selected_state(true)
    #
    def set_selected_state(state)
      obj, _ = find_element
      object_not_found_exception(obj, 'Radio')
      invalid_object_type_exception(obj, 'radio')
      begin
        obj.set(state)
      rescue
        unless state == obj.checked?
          check_id = obj.native.attribute('id')
          label = first("label[for='#{check_id}']")
          label.click if label.exists?
        end
      end
    end

    # Set the selected state of a radio button object.
    #
    # @example
    #   accept_terms_radio.select
    #
    def select
      set_selected_state(true)
    end

    # Unselect a radio button object.
    #
    # @example
    #   accept_terms_radio.unselect
    #
    def unselect
      set_selected_state(false)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
testcentricity_web-0.7.2 lib/testcentricity_web/elements/radio.rb
testcentricity_web-0.7.1 lib/testcentricity_web/elements/radio.rb