Class: RAutomation::Adapter::MsUia::Control

Inherits:
Object
  • Object
show all
Includes:
Locators, WaitHelper
Defined in:
lib/rautomation/adapter/ms_uia/control.rb

Instance Method Summary collapse

Constructor Details

#initialize(window, locators) ⇒ Control

Note:

this method is not meant to be accessed directly

Creates the control object.

Parameters:

  • window (RAutomation::Window)

    this button belongs to.

  • locators (Hash)

    for searching the button.

Options Hash (locators):

  • :value (String, Regexp)

    Value (text) of the button

  • :class (String, Regexp)

    Internal class name of the button

  • :id (String, Integer)

    Internal ID of the button

  • :index (String, Integer)

    0-based index to specify n-th button if all other criteria match

  • :children_only (String, Boolean)

    limit the scope of the search to children only

See Also:



18
19
20
21
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 18

def initialize(window, locators)
  @window = window
  extract(locators)
end

Instance Method Details

#assert_enabled



117
118
119
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 117

def assert_enabled
  raise "Cannot interact with disabled control #{@locators.inspect} on window #{@window.locators.inspect}!" if disabled?
end

#bounding_rectangle



83
84
85
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 83

def bounding_rectangle
  UiaDll::bounding_rectangle(search_information)
end

#cached_hwnd



23
24
25
26
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 23

def cached_hwnd
  @cached_hwnd ||= UiaDll::cached_hwnd(UiaDll::SearchCriteria.from_locator(@window.hwnd, @locators))
  @cached_hwnd == 0 ? nil : @cached_hwnd
end

#click

todo - replace with UIA version



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 44

def click
  assert_enabled
  clicked = false
  wait_until do
    @window.activate
    @window.active? &&
        UiaDll::control_click(search_information) &&
        clicked = true # is clicked at least once

    block_given? ? yield : clicked && !exist?
  end
end

#collapse(which_item)



126
127
128
129
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 126

def collapse(which_item)
  UiaDll::collapse_by_value search_information, which_item if which_item.is_a? String
  UiaDll::collapse_by_index search_information, which_item if which_item.is_a? Integer
end

#control_class



111
112
113
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 111

def control_class
  UiaDll::class_name(search_information)
end

#control_name



103
104
105
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 103

def control_name
  UiaDll::name(search_information)
end

#disabled?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 69

def disabled?
  !enabled?
end

#enabled?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 65

def enabled?
  UiaDll::is_enabled(search_information)
end

#exist?Boolean Also known as: exists?

Returns:

  • (Boolean)


57
58
59
60
61
62
63
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 57

def exist?
  begin
    UiaDll::exists?(search_information) || !!hwnd
  rescue UnknownElementException
    false
  end
end

#expand(which_item)



121
122
123
124
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 121

def expand(which_item)
  UiaDll::expand_by_value search_information, which_item if which_item.is_a? String
  UiaDll::expand_by_index search_information, which_item if which_item.is_a? Integer
end

#focus



78
79
80
81
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 78

def focus
  assert_enabled
  UiaDll::set_focus(search_information)
end

#focused?Boolean

todo - replace with UIA version

Returns:

  • (Boolean)


74
75
76
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 74

def focused?
  UiaDll::is_focused(search_information)
end

#get_current_control_type



95
96
97
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 95

def get_current_control_type
  UiaDll::current_control_type(search_information)
end

#help_text



107
108
109
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 107

def help_text
  UiaDll::help_text(search_information)
end

#hwnd

todo - replace with UIA version



29
30
31
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 29

def hwnd
  Functions.control_hwnd(@window.hwnd, @locators)
end

#matches_type?(*classes) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 91

def matches_type?(*classes)
  classes.include? get_current_control_type
end

#new_pid



99
100
101
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 99

def new_pid
  UiaDll::process_id(search_information)
end

#search_information



33
34
35
36
37
38
39
40
41
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 33

def search_information
  info = UiaDll::SearchCriteria.from_locator(@window.hwnd, @locators)
  if info.how == 0 || cached_hwnd
    info.how = :hwnd
    info.data = cached_hwnd || hwnd
  end

  info
end

#visible?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 87

def visible?
  !UiaDll::is_offscreen(search_information)
end