Class: RAutomation::Adapter::WinFfi::Control

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

Direct Known Subclasses

Button, Checkbox, Label, ListBox, Radio, SelectList, Table, TextField

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/win_ffi/control.rb', line 17

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

Instance Method Details

#assert_enabled



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

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

#click



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rautomation/adapter/win_ffi/control.rb', line 22

def click
  assert_enabled
  clicked = false
  wait_until do
    hwnd = Functions.control_hwnd(@window.hwnd, @locators)

    @window.activate
    @window.active? &&
      Functions.set_control_focus(hwnd) &&
      Functions.control_click(hwnd) &&
      clicked = true # is clicked at least once

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

#disabled?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/rautomation/adapter/win_ffi/control.rb', line 46

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

#enabled?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/rautomation/adapter/win_ffi/control.rb', line 42

def enabled?
  !disabled?
end

#exist?Boolean Also known as: exists?

Returns:

  • (Boolean)


38
39
40
# File 'lib/rautomation/adapter/win_ffi/control.rb', line 38

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

#has_focus?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/rautomation/adapter/win_ffi/control.rb', line 50

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

#matches_type(clazz)



67
68
69
# File 'lib/rautomation/adapter/win_ffi/control.rb', line 67

def matches_type(clazz)
  UiaDll::current_control_type(uia_control(@locators[:id])) == clazz
end

#set_focus



54
55
56
57
58
# File 'lib/rautomation/adapter/win_ffi/control.rb', line 54

def set_focus
  assert_enabled
  uia_control = UiaDll::element_from_handle(Functions.control_hwnd(@window.hwnd, @locators))
  UiaDll::set_focus(uia_control)
end

#uia_control(automation_id)



60
61
62
63
64
65
# File 'lib/rautomation/adapter/win_ffi/control.rb', line 60

def uia_control(automation_id)
  uia_window = UiaDll::element_from_handle(@window.hwnd) # finds IUIAutomationElement for given parent window
  uia_element = UiaDll::find_child_by_id(uia_window, automation_id.to_s)
  fail "Cannot find UIAutomationElement" if uia_element.nil?
  uia_element
end