Class: RAutomation::Adapter::WinFfi::Window

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locators) ⇒ Window

Note:

this method is not meant to be accessed directly, but only through Window#initialize!

Creates the window object.

Parameters:

  • locators (Hash)

    for searching the window.

Options Hash (locators):

  • :title (String, Regexp)

    Title of the window

  • :text (String, Regexp)

    Visible text of the window

  • :class (String, Regexp)

    Internal class name of the window

  • :hwnd (String, Fixnum)

    Window handle in decimal format

  • :pid (String, Fixnum)

    Window process ID (PID)

  • :index (String, Fixnum)

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

See Also:



39
40
41
# File 'lib/rautomation/adapter/win_ffi/window.rb', line 39

def initialize(locators)
  extract(locators)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args)

Redirects all method calls not part of the public API to the Functions directly.



174
175
176
# File 'lib/rautomation/adapter/win_ffi/window.rb', line 174

def method_missing(name, *args)
  Functions.respond_to?(name) ? Functions.send(name, *args) : super
end

Instance Attribute Details

#locators (readonly)

Locators of the window.



24
25
26
# File 'lib/rautomation/adapter/win_ffi/window.rb', line 24

def locators
  @locators
end

Class Method Details

.oleacc_module_handle



14
15
16
17
18
19
20
# File 'lib/rautomation/adapter/win_ffi/window.rb', line 14

def oleacc_module_handle
  @oleacc_module_handle ||= begin
                              oleacc = Functions.load_library "oleacc.dll"
                              Functions.co_initialize nil                                        
                              oleacc
                            end
end

Instance Method Details

#activate

See Also:



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

def activate
  return if !exists? || active?
  restore if minimized?
  Functions.activate_window(hwnd)
  sleep 1
end

#active?Boolean

Returns:

  • (Boolean)

See Also:



69
70
71
# File 'lib/rautomation/adapter/win_ffi/window.rb', line 69

def active?
  exists? && Functions.foreground_window == hwnd
end

#button(locator)



146
147
148
# File 'lib/rautomation/adapter/win_ffi/window.rb', line 146

def button(locator)
  Button.new(self, locator)
end

#close

See Also:



140
141
142
# File 'lib/rautomation/adapter/win_ffi/window.rb', line 140

def close
  Functions.close_window(hwnd)
end

#control(locator)



160
161
162
# File 'lib/rautomation/adapter/win_ffi/window.rb', line 160

def control(locator)
  Control.new(self, locator)
end

#controls(locator)



164
165
166
# File 'lib/rautomation/adapter/win_ffi/window.rb', line 164

def controls(locator)
  Controls.new(self, locator)
end

#exists?Boolean

Returns:

  • (Boolean)

See Also:



79
80
81
82
# File 'lib/rautomation/adapter/win_ffi/window.rb', line 79

def exists?
  result = hwnd && Functions.window_exists(hwnd)
  !!result
end

#hwnd

Note:

Searches only for visible windows.

Retrieves handle of the window.

See Also:



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

def hwnd
  @hwnd ||= Functions.window_hwnd(@locators)
end

#label(locator)



156
157
158
# File 'lib/rautomation/adapter/win_ffi/window.rb', line 156

def label(locator)
  Label.new(self, locator)
end

#list_box(locator)



168
169
170
# File 'lib/rautomation/adapter/win_ffi/window.rb', line 168

def list_box(locator)
  ListBox.new(self, locator)
end

#maximize

See Also:



90
91
92
93
# File 'lib/rautomation/adapter/win_ffi/window.rb', line 90

def maximize
  Functions.show_window(hwnd, Constants::SW_MAXIMIZE)
  sleep 1
end

#minimize

See Also:



96
97
98
99
# File 'lib/rautomation/adapter/win_ffi/window.rb', line 96

def minimize
  Functions.show_window(hwnd, Constants::SW_MINIMIZE)
  sleep 1
end

#minimized?Boolean

Returns:

  • (Boolean)

See Also:



102
103
104
# File 'lib/rautomation/adapter/win_ffi/window.rb', line 102

def minimized?
  Functions.minimized(hwnd)
end

#pid

See Also:



51
52
53
# File 'lib/rautomation/adapter/win_ffi/window.rb', line 51

def pid
  Functions.window_pid(hwnd)
end

#restore

See Also:



107
108
109
110
# File 'lib/rautomation/adapter/win_ffi/window.rb', line 107

def restore
  Functions.show_window(hwnd, Constants::SW_RESTORE)
  sleep 1
end

#send_keys(keys)

Activates the window and sends keys to it.

Refer to KeystrokeConverter#convert_special_characters for the special keycodes.

See Also:



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/rautomation/adapter/win_ffi/window.rb', line 116

def send_keys(keys)
  shift_pressed = false
  KeystrokeConverter.convert(keys).each do |key|
    wait_until do
      activate
      active?
    end
    press_key key

    if key == Constants::VK_LSHIFT
      shift_pressed = true
      next
    end

    release_key key

    if shift_pressed
      shift_pressed = false
      release_key Constants::VK_LSHIFT
    end
  end
end

#text

See Also:



74
75
76
# File 'lib/rautomation/adapter/win_ffi/window.rb', line 74

def text
  Functions.window_text(hwnd)
end

#text_field(locator)



152
153
154
# File 'lib/rautomation/adapter/win_ffi/window.rb', line 152

def text_field(locator)
  TextField.new(self, locator)
end

#title

See Also:



56
57
58
# File 'lib/rautomation/adapter/win_ffi/window.rb', line 56

def title
  Functions.window_title(hwnd)
end

#visible?Boolean

Returns:

  • (Boolean)

See Also:



85
86
87
# File 'lib/rautomation/adapter/win_ffi/window.rb', line 85

def visible?
  Functions.window_visible(hwnd)
end