Sha256: 05d14400b15183e1439d403165240931205e03d3bf4c4c06f9e287f2afe5dff0

Contents?: true

Size: 1.41 KB

Versions: 21

Compression:

Stored size: 1.41 KB

Contents

module TestCentricity
  module AppElements
    class AppSwitch < AppUIElement
      def initialize(name, parent, locator, context)
        super
        @type = :switch
      end

      # Is switch in ON state?
      #
      # @return [Boolean]
      # @example
      #   use_face_id_switch.on?
      #
      def on?
        obj = element
        object_not_found_exception(obj)

        if Environ.is_ios?
          state =  obj.attribute(:value)
          state.to_bool
        else
          state = obj.attribute(:checked)
          state.boolean? ? state : state == 'true'
        end
      end

      alias checked? on?
      alias selected? on?

      # Set the state of a switch object to ON.
      #
      # @example
      #   use_face_id_switch.on
      #
      def on
        obj = element
        object_not_found_exception(obj)
        obj.click unless on?
      end

      # Set the state of a switch object to OFF.
      #
      # @example
      #   use_face_id_switch.off
      #
      def off
        obj = element
        object_not_found_exception(obj)
        obj.click if on?
      end

      # Set the ON/OFF state of a switch object.
      #
      # @param state [Boolean] true = on / false = off
      # @example
      #   use_face_id_switch.set_switch_state(true)
      #
      def set_switch_state(state)
        obj = element
        object_not_found_exception(obj)
        state ? on : off
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
testcentricity_apps-4.0.15 lib/testcentricity_apps/app_elements/switch.rb
testcentricity_mobile-4.0.14 lib/testcentricity_mobile/app_elements/switch.rb
testcentricity_apps-4.0.14 lib/testcentricity_apps/app_elements/switch.rb
testcentricity_mobile-4.0.13 lib/testcentricity_mobile/app_elements/switch.rb
testcentricity_apps-4.0.13 lib/testcentricity_apps/app_elements/switch.rb
testcentricity_mobile-4.0.12 lib/testcentricity_mobile/app_elements/switch.rb
testcentricity_apps-4.0.12 lib/testcentricity_apps/app_elements/switch.rb
testcentricity_mobile-4.0.11 lib/testcentricity_mobile/app_elements/switch.rb
testcentricity_apps-4.0.11 lib/testcentricity_apps/app_elements/switch.rb
testcentricity_mobile-4.0.10 lib/testcentricity_mobile/app_elements/switch.rb
testcentricity_apps-4.0.10 lib/testcentricity_apps/app_elements/switch.rb
testcentricity_mobile-4.0.9 lib/testcentricity_mobile/app_elements/switch.rb
testcentricity_mobile-4.0.8 lib/testcentricity_mobile/app_elements/switch.rb
testcentricity_mobile-4.0.7 lib/testcentricity_mobile/app_elements/switch.rb
testcentricity_mobile-4.0.6 lib/testcentricity_mobile/app_elements/switch.rb
testcentricity_mobile-4.0.5 lib/testcentricity_mobile/app_elements/switch.rb
testcentricity_mobile-4.0.4 lib/testcentricity_mobile/app_elements/switch.rb
testcentricity_mobile-4.0.3 lib/testcentricity_mobile/app_elements/switch.rb
testcentricity_mobile-4.0.2 lib/testcentricity_mobile/app_elements/switch.rb
testcentricity_mobile-4.0.1 lib/testcentricity_mobile/app_elements/switch.rb