Sha256: 769f9f3ebeda4005b86a601a2236e43f6e4d5aaaee2e327ca5f96ed0fe289d16

Contents?: true

Size: 1.57 KB

Versions: 6

Compression:

Stored size: 1.57 KB

Contents

module TestCentricity
  class Radio < UIElement
    attr_accessor :proxy

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

    # Does radio button object exists?
    #
    # @return [Boolean]
    # @example
    #   accept_terms_radio.exists?
    #
    def exists?
      obj, _ = find_object(:all)
      obj != nil
    end

    # Is radio button selected?
    #
    # @return [Boolean]
    # @example
    #   accept_terms_radio.selected?
    #
    def selected?
      obj, _ = find_element(:all)
      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(:all)
      object_not_found_exception(obj, 'Radio')
      invalid_object_type_exception(obj, 'radio')
      if @proxy.nil?
        obj.set(state)
      else
        @proxy.click unless state == obj.checked?
      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

6 entries across 6 versions & 1 rubygems

Version Path
testcentricity_web-1.0.16 lib/testcentricity_web/elements/radio.rb
testcentricity_web-1.0.15 lib/testcentricity_web/elements/radio.rb
testcentricity_web-1.0.14 lib/testcentricity_web/elements/radio.rb
testcentricity_web-1.0.13 lib/testcentricity_web/elements/radio.rb
testcentricity_web-1.0.12 lib/testcentricity_web/elements/radio.rb
testcentricity_web-1.0.11 lib/testcentricity_web/elements/radio.rb