Class: RAutomation::Adapter::MsUia::Window

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container, locators) ⇒ Window

Note:

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

Possible locators are :title, :text, :hwnd, :pid, :class and :index. todo - update list of valid locators for UIA 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, Integer)

    Window handle in decimal format

  • :pid (String, Integer)

    Window process ID (PID)

  • :index (String, Integer)

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

See Also:



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

def initialize(container, locators)
  @container = container
  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.



191
192
193
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 191

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

Instance Attribute Details

#locators (readonly)

Locators of the window.



14
15
16
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 14

def locators
  @locators
end

Instance Method Details

#activate

See Also:



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

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

#active?Boolean

todo - replace with UIA version

Returns:

  • (Boolean)

See Also:



71
72
73
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 71

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

#bounding_rectangle



195
196
197
198
199
200
201
202
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 195

def bounding_rectangle
  window = UiaDll::element_from_handle(hwnd)

  boundary = FFI::MemoryPointer.new :long, 4
  UiaDll::bounding_rectangle(window, boundary)

  boundary.read_array_of_long(4)
end

#button(locator)



159
160
161
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 159

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

#checkbox(locator)



242
243
244
245
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 242

def checkbox(locator)
  @container.wait_until_present
  Checkbox.new(self, locator)
end

#child(locators) ⇒ RAutomation::Window

Note:

This is an Win32 adapter specific method, not part of the public API

todo - replace with UIA version Creates the child window object.

Examples:

RAutomation::Window.new(:title => /Windows Internet Explorer/i).
  child(:title => /some popup/)

Parameters:

  • locators (Hash)

    for searching the window.

Returns:



265
266
267
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 265

def child(locators)
  RAutomation::Window.new Functions.child_window_locators(hwnd, locators)
end

#class_names

See Also:



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

def class_names
  classes = UiaDll::children_class_names(UiaDll::SearchCriteria.from_locator(hwnd, :hwnd => hwnd))
  classes.delete_if(&:empty?).sort
end

#click_mouse



208
209
210
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 208

def click_mouse()
  UiaDll::click_mouse
end

#close

todo - replace with UIA version

See Also:



153
154
155
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 153

def close
  Functions.close_window(hwnd)
end

#control(locator)



217
218
219
220
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 217

def control(locator)
  @container.wait_until_present
  Control.new(self, locator)
end

#controls(locator)



222
223
224
225
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 222

def controls(locator)
  @container.wait_until_present
  Controls.new(self, locator)
end

#exists?Boolean

todo - replace with UIA version

Returns:

  • (Boolean)

See Also:



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

def exists?
  hwnd && Functions.window_exists(hwnd)
end

#hwnd

Note:

Searches only for visible windows.

todo - replace with UIA version Retrieves handle of the window.

See Also:



38
39
40
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 38

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

#label(locator)



212
213
214
215
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 212

def label(locator)
  @container.wait_until_present
  Label.new(self, locator)
end

#list_box(locator)



227
228
229
230
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 227

def list_box(locator)
  @container.wait_until_present
  ListBox.new(self, locator)
end

#list_item(locator)



232
233
234
235
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 232

def list_item(locator)
  @container.wait_until_present
  ListItem.new(self, locator)
end

#maximize

todo - replace with UIA version

See Also:



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

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

Returns a Menu object use to build a path to a menu item to open.

Parameters:

  • locator (Hash)

    for the Menu. Only :text is allowed.



185
186
187
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 185

def menu(locator)
  Menu.new(self, locator)
end

#minimize

todo - replace with UIA version

See Also:



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

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

#minimized?Boolean

todo - replace with UIA version

Returns:

  • (Boolean)

See Also:



109
110
111
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 109

def minimized?
  Functions.minimized(hwnd)
end

#move_mouse(x, y)



204
205
206
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 204

def move_mouse(x, y)
  UiaDll::move_mouse(x, y)
end

#pid

todo - replace with UIA version

See Also:



44
45
46
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 44

def pid
  Functions.window_pid(hwnd)
end

#radio(locator)



247
248
249
250
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 247

def radio(locator)
  @container.wait_until_present
  Radio.new(self, locator)
end

#restore

todo - replace with UIA version

See Also:



115
116
117
118
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 115

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

#select_list(locator)



237
238
239
240
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 237

def select_list(locator)
  @container.wait_until_present
  SelectList.new(self, locator)
end

#send_keys(args)

Activates the window and sends keys to it.

Refer to Keys::KEYS for all the special keycodes.

Examples:

RAutomation::Window.new(:title => //).send_keys "hello!"
RAutomation::Window.new(:title => //).send_keys [:control, "a"], "world!"

See Also:



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 127

def send_keys(args)
  Keys.encode(args).each do |arg|
    wait_until do
      activate
      active?
    end

    if arg.is_a?(Array)
      arg.reduce([]) do |pressed_keys, k|
        if k == Keys[:null]
          pressed_keys.each {|pressed_key| release_key pressed_key}
          pressed_keys = []
        else
          pressed_keys << press_key(k)
        end
        pressed_keys
      end
    else
      send_key arg
    end
  end
  sleep 1
end

#spinner(locator)

See Also:



173
174
175
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 173

def spinner(locator)
  Spinner.new(self, locator)
end

#tab_control(locator)

See Also:



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

def tab_control(locator)
  TabControl.new(self, locator)
end

#table(locator)



252
253
254
255
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 252

def table(locator)
  @container.wait_until_present
  Table.new(self, locator)
end

#text

todo - replace with UIA version

See Also:



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

def text
  Functions.window_text(hwnd)
end

#text_field(locator)



179
180
181
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 179

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

#title

todo - replace with UIA version

See Also:



50
51
52
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 50

def title
  Functions.window_title(hwnd)
end

#value_control(locator)



163
164
165
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 163

def value_control(locator)
  ValueControl.new(self, locator)
end

#visible?Boolean

todo - replace with UIA version

Returns:

  • (Boolean)

See Also:



89
90
91
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 89

def visible?
  Functions.window_visible(hwnd)
end