Sha256: 4553128861e9b6ea7c37622cee26f2be1e5a98d6d7ce06aa273ef192403f053c

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

module Mohawk
  module Adapters
    module UIA
      class MenuItem < Control
        class MenuItemNotFound < StandardError; end

        def select
          menu_item.as(:invoke).invoke
        end

        def click
          menu_item.click_center
        end

        def exist?
          !!menu_item
        rescue MenuItemNotFound
          false
        end
        alias_method :exists?, :exist?

        private
        def menu_item
          current_item = @parent
          path.each_with_index do |menu_item, index|
            current_item = current_item.filter(control_type: :menu_item, name: menu_item).first
            raise MenuItemNotFound, menu_item unless current_item
            try_to_expand current_item unless index == path.count - 1
          end
          current_item
        end

        def path
          [@locator[:path] || @locator[:text]].flatten
        end

        def try_to_expand(item)
          case
            when item.patterns.include?(:expand_collapse)
              item.as(:expand_collapse).expand
            else
              item.as(:invoke).invoke
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mohawk-0.2 lib/mohawk/adapters/uia/menu_item.rb