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, Fixnum)

    Internal ID of the button

  • :index (String, Fixnum)

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

See Also:



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

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

Instance Method Details

#assert_enabled



124
125
126
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 124

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

#bounding_rectangle



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

def bounding_rectangle
  UiaDll::bounding_rectangle(search_information)
end

#cached_hwnd



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

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



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

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)



133
134
135
136
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 133

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



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

def control_class
  UiaDll::class_name(search_information)
end

#control_name



114
115
116
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 114

def control_name
  UiaDll::name(search_information)
end

#disabled?Boolean

Returns:

  • (Boolean)


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

def disabled?
  !enabled?
end

#enabled?Boolean

Returns:

  • (Boolean)


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

def enabled?
  UiaDll::is_enabled(search_information)
end

#exist?Boolean Also known as: exists?

Returns:

  • (Boolean)


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

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

#expand(which_item)



128
129
130
131
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 128

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



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

def focus
  assert_enabled
  UiaDll::set_focus(search_information)
end

#focused?Boolean

todo - replace with UIA version

Returns:

  • (Boolean)


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

def focused?
  UiaDll::is_focused(search_information)
end

#get_current_control_type



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

def get_current_control_type
  UiaDll::current_control_type(search_information)
end

#hwnd

todo - replace with UIA version



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

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

#matches_type?(*classes) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#new_pid



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

def new_pid
  UiaDll::process_id(search_information)
end

#search_information



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

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)


86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/rautomation/adapter/ms_uia/control.rb', line 86

def visible?
  element = UiaDll::element_from_handle(hwnd)

  off_screen = FFI::MemoryPointer.new :int

  if UiaDll::is_offscreen(element, off_screen) == 0
    fail "Could not check element"
  end

#          puts "return #{off_screen.read_int}"
  if off_screen.read_int == 0
    return true
  end
  false
end