rautomation 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +14 -0
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/ext/IAccessibleDLL/IAccessibleDLL.suo +0 -0
- data/ext/IAccessibleDLL/IAccessibleDLL/IAccessibleDLL.cpp +0 -6
- data/ext/IAccessibleDLL/IAccessibleDLL/IAccessibleDLL.vcxproj +2 -0
- data/ext/IAccessibleDLL/IAccessibleDLL/IAccessibleDLL.vcxproj.filters +3 -0
- data/ext/IAccessibleDLL/IAccessibleDLL/stdafx.h +9 -3
- data/ext/IAccessibleDLL/IAccessibleDLL/table_support.cpp +282 -0
- data/ext/IAccessibleDLL/Release/IAccessibleDLL.dll +0 -0
- data/ext/ListViewExplorer/ListViewExplorer.sln +20 -0
- data/ext/ListViewExplorer/ListViewExplorer.suo +0 -0
- data/ext/ListViewExplorer/ListViewExplorer/ListViewExplorer.cpp +174 -0
- data/ext/ListViewExplorer/ListViewExplorer/ListViewExplorer.vcxproj +95 -0
- data/ext/ListViewExplorer/ListViewExplorer/ListViewExplorer.vcxproj.filters +42 -0
- data/ext/ListViewExplorer/ListViewExplorer/ListViewExplorer.vcxproj.user +3 -0
- data/ext/ListViewExplorer/ListViewExplorer/ReadMe.txt +40 -0
- data/ext/ListViewExplorer/ListViewExplorer/stdafx.cpp +8 -0
- data/ext/ListViewExplorer/ListViewExplorer/stdafx.h +17 -0
- data/ext/ListViewExplorer/ListViewExplorer/table_support.cpp +250 -0
- data/ext/ListViewExplorer/ListViewExplorer/table_support.h +2 -0
- data/ext/ListViewExplorer/ListViewExplorer/targetver.h +8 -0
- data/ext/UiaDll/Release/UiaDll.dll +0 -0
- data/ext/UiaDll/UiaDll.sln +20 -0
- data/ext/UiaDll/UiaDll.suo +0 -0
- data/ext/UiaDll/UiaDll/ReadMe.txt +48 -0
- data/ext/UiaDll/UiaDll/UiaDll.cpp +205 -0
- data/ext/UiaDll/UiaDll/UiaDll.vcxproj +104 -0
- data/ext/UiaDll/UiaDll/UiaDll.vcxproj.filters +42 -0
- data/ext/UiaDll/UiaDll/dllmain.cpp +39 -0
- data/ext/UiaDll/UiaDll/globals.h +3 -0
- data/ext/UiaDll/UiaDll/stdafx.cpp +8 -0
- data/ext/UiaDll/UiaDll/stdafx.h +19 -0
- data/ext/UiaDll/UiaDll/targetver.h +8 -0
- data/ext/WindowsForms/bin/WindowsForms.exe +0 -0
- data/ext/WindowsForms/src/WindowsForms/WindowsForms.suo +0 -0
- data/ext/WindowsForms/src/WindowsForms/WindowsForms/DataEntryForm.Designer.cs +27 -7
- data/ext/WindowsForms/src/WindowsForms/WindowsForms/DataEntryForm.cs +1 -0
- data/ext/WindowsForms/src/WindowsForms/WindowsForms/MainFormWindow.Designer.cs +110 -11
- data/ext/WindowsForms/src/WindowsForms/WindowsForms/bin/Release/WindowsForms.exe +0 -0
- data/lib/rautomation.rb +2 -3
- data/lib/rautomation/adapter/autoit.rb +2 -2
- data/lib/rautomation/adapter/win_ffi.rb +4 -0
- data/lib/rautomation/adapter/win_ffi/button.rb +6 -0
- data/lib/rautomation/adapter/win_ffi/checkbox.rb +7 -0
- data/lib/rautomation/adapter/win_ffi/constants.rb +44 -3
- data/lib/rautomation/adapter/win_ffi/control.rb +36 -3
- data/lib/rautomation/adapter/win_ffi/functions.rb +37 -3
- data/lib/rautomation/adapter/win_ffi/keystroke_converter.rb +67 -0
- data/lib/rautomation/adapter/win_ffi/label.rb +21 -0
- data/lib/rautomation/adapter/win_ffi/list_box.rb +60 -0
- data/lib/rautomation/adapter/win_ffi/locators.rb +0 -1
- data/lib/rautomation/adapter/win_ffi/ms_uia/uia_dll.rb +36 -0
- data/lib/rautomation/adapter/win_ffi/radio.rb +7 -0
- data/lib/rautomation/adapter/win_ffi/select_list.rb +30 -7
- data/lib/rautomation/adapter/win_ffi/table.rb +42 -3
- data/lib/rautomation/adapter/win_ffi/text_field.rb +17 -1
- data/lib/rautomation/adapter/win_ffi/window.rb +47 -8
- data/lib/rautomation/button.rb +5 -0
- data/lib/rautomation/element_collections.rb +8 -5
- data/lib/rautomation/text_field.rb +10 -0
- data/lib/rautomation/window.rb +20 -14
- data/spec/adapter/win_ffi/button_spec.rb +41 -0
- data/spec/adapter/win_ffi/checkbox_spec.rb +19 -0
- data/spec/adapter/win_ffi/keystroke_converter_spec.rb +47 -0
- data/spec/adapter/win_ffi/label_spec.rb +21 -0
- data/spec/adapter/win_ffi/listbox_spec.rb +52 -0
- data/spec/adapter/win_ffi/radio_spec.rb +16 -0
- data/spec/adapter/win_ffi/select_list_spec.rb +29 -4
- data/spec/adapter/win_ffi/table_spec.rb +20 -1
- data/spec/adapter/win_ffi/text_field_spec.rb +23 -0
- data/spec/adapter/win_ffi/window_spec.rb +29 -0
- data/spec/button_spec.rb +1 -0
- data/spec/spec_helper.rb +4 -1
- data/spec/text_field_spec.rb +27 -15
- metadata +52 -34
- data/ext/IAccessibleDLL/Release/IAccessibleDLL.exp +0 -0
- data/ext/IAccessibleDLL/Release/IAccessibleDLL.lib +0 -0
- data/ext/WindowsForms/src/WindowsForms/WindowsForms/bin/Debug/WindowsForms.exe +0 -0
- data/ext/WindowsForms/src/WindowsForms/WindowsForms/bin/Debug/WindowsForms.pdb +0 -0
- data/ext/WindowsForms/src/WindowsForms/WindowsForms/bin/Debug/WindowsForms.vshost.exe +0 -0
- data/ext/WindowsForms/src/WindowsForms/WindowsForms/bin/Debug/WindowsForms.vshost.exe.manifest +0 -11
- data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/DesignTimeResolveAssemblyReferences.cache +0 -0
- data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache +0 -0
- data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/GenerateResource.read.1.tlog +0 -0
- data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/GenerateResource.write.1.tlog +0 -0
- data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/ResolveAssemblyReference.cache +0 -0
- data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/WindowsForms.AboutBox.resources +0 -0
- data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/WindowsForms.DataEntryForm.resources +0 -0
- data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/WindowsForms.MainFormWindow.resources +0 -0
- data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/WindowsForms.PersonForm.resources +0 -0
- data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/WindowsForms.Properties.Resources.resources +0 -0
- data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/WindowsForms.SimpleElementsForm.resources +0 -0
- data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/WindowsForms.csproj.FileListAbsolute.txt +0 -25
- data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/WindowsForms.exe +0 -0
- data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/WindowsForms.pdb +0 -0
@@ -14,7 +14,7 @@ module RAutomation
|
|
14
14
|
|
15
15
|
SMTO_ABORTIFHUNG = 0x2
|
16
16
|
|
17
|
-
STANDARD_RIGHTS_REQUIRED = 0xF0000
|
17
|
+
STANDARD_RIGHTS_REQUIRED = 0xF0000
|
18
18
|
SYNCHRONIZE = 0x100000
|
19
19
|
PROCESS_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0xFFF
|
20
20
|
|
@@ -26,13 +26,41 @@ module RAutomation
|
|
26
26
|
KEYEVENTF_EXTENDEDKEY = 0x1
|
27
27
|
KEYEVENTF_KEYUP = 0x2
|
28
28
|
|
29
|
+
VK_BACK = 0x08
|
30
|
+
VK_TAB = 0x09
|
31
|
+
VK_RETURN = 0x0D
|
32
|
+
VK_SPACE = 0x20
|
33
|
+
VK_CAPITAL = 0x14
|
34
|
+
VK_LEFT = 0x25
|
35
|
+
VK_UP = 0x26
|
36
|
+
VK_RIGHT = 0x27
|
37
|
+
VK_DOWN = 0x28
|
38
|
+
VK_SHIFT = 0x10
|
39
|
+
VK_LSHIFT = 0xA0
|
40
|
+
VK_RSHIFT = 0xA1
|
41
|
+
VK_MENU = 0x12
|
42
|
+
VK_LMENU = 0xA4
|
43
|
+
VK_RMENU = 0xA5
|
44
|
+
VK_CONTROL = 0x11
|
45
|
+
VK_LCONTROL = 0xA2
|
46
|
+
VK_RCONTROL = 0xA3
|
47
|
+
VK_ESCAPE = 0x1B
|
48
|
+
VK_END = 0x23
|
49
|
+
VK_HOME = 0x24
|
50
|
+
VK_NUMLOCK = 0x90
|
51
|
+
VK_DELETE = 0x2E
|
52
|
+
VK_INSERT = 0x2D
|
53
|
+
|
29
54
|
# GetWindow constants
|
30
55
|
GW_ENABLEDPOPUP = 6
|
31
56
|
|
32
57
|
# HRESULT
|
33
|
-
S_OK
|
58
|
+
S_OK = 0
|
34
59
|
|
35
60
|
# IAccessible Button States
|
61
|
+
STATE_SYSTEM_UNAVAILABLE = 0x00000001
|
62
|
+
STATE_SYSTEM_SELECTED = 0x00000002
|
63
|
+
STATE_SYSTEM_FOCUSED = 0x00000004
|
36
64
|
STATE_SYSTEM_CHECKED = 0x00000010
|
37
65
|
|
38
66
|
# Combobox
|
@@ -47,7 +75,20 @@ module RAutomation
|
|
47
75
|
LVM_FIRST = 0x1000
|
48
76
|
LVM_GETITEMCOUNT = LVM_FIRST + 4
|
49
77
|
|
78
|
+
# UI Automation control type IDs
|
79
|
+
UIA_LIST_CONTROL_TYPE = 50008
|
80
|
+
UIA_LIST_ITEM_CONTROL_TYPE = 50007
|
81
|
+
UIA_CHECKBOX_CONTROL_TYPE = 50002
|
82
|
+
UIA_BUTTON_CONTROL_TYPE = 50000
|
83
|
+
UIA_LABEL_CONTROL_TYPE = 50020
|
84
|
+
UIA_RADIO_BUTTON_CONTROL_TYPE = 50013
|
85
|
+
UIA_COMBOBOX_CONTROL_TYPE = 50003
|
86
|
+
UIA_EDIT_CONTROL_TYPE = 50004
|
87
|
+
UIA_HEADER_CONTROL_TYPE = 50034
|
88
|
+
UIA_HEADER_ITEM_CONTROL_TYPE = 50035
|
89
|
+
|
90
|
+
|
50
91
|
end
|
51
92
|
end
|
52
93
|
end
|
53
|
-
end
|
94
|
+
end
|
@@ -20,15 +20,16 @@ module RAutomation
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def click
|
23
|
+
assert_enabled
|
23
24
|
clicked = false
|
24
25
|
wait_until do
|
25
26
|
hwnd = Functions.control_hwnd(@window.hwnd, @locators)
|
26
27
|
|
27
28
|
@window.activate
|
28
29
|
@window.active? &&
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
Functions.set_control_focus(hwnd) &&
|
31
|
+
Functions.control_click(hwnd) &&
|
32
|
+
clicked = true # is clicked at least once
|
32
33
|
|
33
34
|
block_given? ? yield : clicked && !exist?
|
34
35
|
end
|
@@ -38,8 +39,40 @@ module RAutomation
|
|
38
39
|
!!Functions.control_hwnd(@window.hwnd, @locators)
|
39
40
|
end
|
40
41
|
|
42
|
+
def enabled?
|
43
|
+
!disabled?
|
44
|
+
end
|
45
|
+
|
46
|
+
def disabled?
|
47
|
+
Functions.unavailable?(Functions.control_hwnd(@window.hwnd, @locators))
|
48
|
+
end
|
49
|
+
|
50
|
+
def has_focus?
|
51
|
+
Functions.has_focus?(Functions.control_hwnd(@window.hwnd, @locators))
|
52
|
+
end
|
53
|
+
|
54
|
+
def set_focus
|
55
|
+
assert_enabled
|
56
|
+
uia_control = UiaDll::element_from_handle(Functions.control_hwnd(@window.hwnd, @locators))
|
57
|
+
UiaDll::set_focus(uia_control)
|
58
|
+
end
|
59
|
+
|
60
|
+
def uia_control(automation_id)
|
61
|
+
uia_window = UiaDll::element_from_handle(@window.hwnd) # finds IUIAutomationElement for given parent window
|
62
|
+
uia_element = UiaDll::find_child_by_id(uia_window, automation_id.to_s)
|
63
|
+
fail "Cannot find UIAutomationElement" if uia_element.nil?
|
64
|
+
uia_element
|
65
|
+
end
|
66
|
+
|
67
|
+
def matches_type(clazz)
|
68
|
+
UiaDll::current_control_type(uia_control(@locators[:id])) == clazz
|
69
|
+
end
|
70
|
+
|
41
71
|
alias_method :exists?, :exist?
|
42
72
|
|
73
|
+
def assert_enabled
|
74
|
+
raise "Cannot interact with disabled control #{@locators.inspect} on window #{@window.locators.inspect}!" if disabled?
|
75
|
+
end
|
43
76
|
end
|
44
77
|
end
|
45
78
|
end
|
@@ -78,6 +78,12 @@ module RAutomation
|
|
78
78
|
# iaccessible
|
79
79
|
attach_function :get_button_state, :get_button_state,
|
80
80
|
[:long], :long
|
81
|
+
attach_function :get_table_row_strings, :get_table_row_strings,
|
82
|
+
[:long, :long, :pointer, :long, :pointer], :void
|
83
|
+
attach_function :select_table_row, :select_table_row,
|
84
|
+
[:long, :long, :long], :void
|
85
|
+
attach_function :get_table_row_state, :get_table_row_state,
|
86
|
+
[:long, :long, :long], :long
|
81
87
|
|
82
88
|
class << self
|
83
89
|
|
@@ -174,8 +180,16 @@ module RAutomation
|
|
174
180
|
end
|
175
181
|
|
176
182
|
def control_hwnd(window_hwnd, locators)
|
177
|
-
|
178
|
-
|
183
|
+
if locators[:id].nil?
|
184
|
+
find_hwnd(locators, window_hwnd) do |hwnd|
|
185
|
+
locators_match?(locators, control_properties(hwnd, locators))
|
186
|
+
end
|
187
|
+
else
|
188
|
+
uia_window = UiaDll::element_from_handle(window_hwnd) # finds IUIAutomationElement for given parent window
|
189
|
+
uia_control = UiaDll::find_child_by_id(uia_window, locators[:id].to_s)
|
190
|
+
hwnd = UiaDll::current_native_window_handle(uia_control) # return HWND of UIA element
|
191
|
+
raise UnknownElementException, "#{locators[:id]} does not exist" if hwnd == 0
|
192
|
+
hwnd
|
179
193
|
end
|
180
194
|
end
|
181
195
|
|
@@ -203,6 +217,14 @@ module RAutomation
|
|
203
217
|
get_button_state(control_hwnd) & Constants::STATE_SYSTEM_CHECKED != 0
|
204
218
|
end
|
205
219
|
|
220
|
+
def has_focus?(control_hwnd)
|
221
|
+
get_button_state(control_hwnd) & Constants::STATE_SYSTEM_FOCUSED != 0
|
222
|
+
end
|
223
|
+
|
224
|
+
def unavailable?(control_hwnd)
|
225
|
+
get_button_state(control_hwnd) & Constants::STATE_SYSTEM_UNAVAILABLE != 0
|
226
|
+
end
|
227
|
+
|
206
228
|
def retrieve_combobox_item_text(control_hwnd, item_no)
|
207
229
|
text_len = send_message(control_hwnd, Constants::CB_GETLBTEXTLEN, item_no, nil)
|
208
230
|
|
@@ -212,7 +234,6 @@ module RAutomation
|
|
212
234
|
end
|
213
235
|
|
214
236
|
def control_name(control_hwnd)
|
215
|
-
puts "Trying to get control name for #{control_hwnd}"
|
216
237
|
string_buffer = FFI::MemoryPointer.new :char, 255
|
217
238
|
if (get_control_name(control_hwnd, string_buffer) == Constants::S_OK)
|
218
239
|
string_buffer.read_string
|
@@ -221,6 +242,19 @@ module RAutomation
|
|
221
242
|
end
|
222
243
|
end
|
223
244
|
|
245
|
+
def retrieve_table_strings_for_row(control_hwnd, row)
|
246
|
+
hModule = load_library("oleacc.dll") # TODO should be done only one time
|
247
|
+
|
248
|
+
strings_ptr = FFI::MemoryPointer.new :pointer
|
249
|
+
columns_ptr = FFI::MemoryPointer.new :pointer
|
250
|
+
|
251
|
+
get_table_row_strings(hModule, control_hwnd, strings_ptr, row, columns_ptr)
|
252
|
+
str_ptr = strings_ptr.read_pointer
|
253
|
+
columns = columns_ptr.read_long
|
254
|
+
|
255
|
+
str_ptr.get_array_of_string(0, columns)
|
256
|
+
end
|
257
|
+
|
224
258
|
private
|
225
259
|
|
226
260
|
def within_foreground_thread(hwnd)
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module RAutomation
|
2
|
+
module Adapter
|
3
|
+
module WinFfi
|
4
|
+
class KeystrokeConverter
|
5
|
+
class << self
|
6
|
+
def convert(str)
|
7
|
+
special_characters = ""
|
8
|
+
|
9
|
+
str.split(/([{}])/).inject([]) do |converted_keys, str|
|
10
|
+
if str == "}"
|
11
|
+
converted_keys << convert_special_characters(special_characters << str)
|
12
|
+
special_characters = ""
|
13
|
+
elsif str == "{" || !special_characters.empty?
|
14
|
+
special_characters << str
|
15
|
+
else
|
16
|
+
converted_keys += convert_characters(str)
|
17
|
+
end
|
18
|
+
converted_keys
|
19
|
+
end.flatten
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def convert_special_characters chars
|
25
|
+
case chars.downcase
|
26
|
+
when "{tab}"
|
27
|
+
Constants::VK_TAB
|
28
|
+
when "{backspace}"
|
29
|
+
Constants::VK_BACK
|
30
|
+
when "{enter}"
|
31
|
+
Constants::VK_RETURN
|
32
|
+
when "{left}"
|
33
|
+
Constants::VK_LEFT
|
34
|
+
when "{right}"
|
35
|
+
Constants::VK_RIGHT
|
36
|
+
when "{down}"
|
37
|
+
Constants::VK_DOWN
|
38
|
+
when "{up}"
|
39
|
+
Constants::VK_UP
|
40
|
+
else
|
41
|
+
# unsupported special tag, ignore the tag itself, but convert the
|
42
|
+
# characters inside the tag
|
43
|
+
convert_characters(chars.gsub(/[{}]/, ""))
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def convert_characters(element)
|
50
|
+
element.split(//).inject([]) do |chars, char|
|
51
|
+
char_code = char.upcase.unpack("c")[0]
|
52
|
+
if char =~ /[A-Z]/
|
53
|
+
chars += in_upcase(char_code)
|
54
|
+
else
|
55
|
+
chars << char_code
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def in_upcase(char_code)
|
61
|
+
[Constants::VK_LSHIFT, char_code]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module RAutomation
|
2
|
+
module Adapter
|
3
|
+
module WinFfi
|
4
|
+
class Label < Control
|
5
|
+
include WaitHelper
|
6
|
+
include Locators
|
7
|
+
|
8
|
+
def value
|
9
|
+
Functions.control_value(Functions.control_hwnd(@window.hwnd, @locators))
|
10
|
+
end
|
11
|
+
|
12
|
+
def exist?
|
13
|
+
@locators[:id].nil? ? super : super && matches_type(Constants::UIA_LABEL_CONTROL_TYPE)
|
14
|
+
end
|
15
|
+
|
16
|
+
alias_method :exists?, :exist?
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module RAutomation
|
2
|
+
module Adapter
|
3
|
+
module WinFfi
|
4
|
+
|
5
|
+
class ListBox < Control
|
6
|
+
include WaitHelper
|
7
|
+
include Locators
|
8
|
+
|
9
|
+
def count
|
10
|
+
UiaDll::find_children(uia_control(@locators[:id]), nil)
|
11
|
+
end
|
12
|
+
|
13
|
+
def items
|
14
|
+
list_items = []
|
15
|
+
children = FFI::MemoryPointer.new :pointer, self.count
|
16
|
+
length = UiaDll::find_children(uia_control(@locators[:id]), children)
|
17
|
+
children.read_array_of_pointer(length).each do |child|
|
18
|
+
child_name = FFI::MemoryPointer.new :char, UiaDll::get_name(child, nil) + 1
|
19
|
+
UiaDll::get_name(child, child_name)
|
20
|
+
list_items.push child_name.read_string
|
21
|
+
end
|
22
|
+
list_items
|
23
|
+
end
|
24
|
+
|
25
|
+
def exist?
|
26
|
+
@locators[:id].nil? ? super : super && matches_type(Constants::UIA_LIST_CONTROL_TYPE)
|
27
|
+
end
|
28
|
+
|
29
|
+
alias_method :exists?, :exist?
|
30
|
+
|
31
|
+
def selected?(index)
|
32
|
+
children = FFI::MemoryPointer.new :pointer, self.count
|
33
|
+
length = UiaDll::find_children(uia_control(@locators[:id]), children)
|
34
|
+
target_element = children.read_array_of_pointer(length)[index]
|
35
|
+
is_selected = FFI::MemoryPointer.new :int, 1
|
36
|
+
|
37
|
+
if UiaDll::get_is_selected(target_element, is_selected) == 1
|
38
|
+
return is_selected.read_int == 1
|
39
|
+
else
|
40
|
+
return false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def select(index)
|
45
|
+
children = FFI::MemoryPointer.new :pointer, self.count
|
46
|
+
|
47
|
+
length = UiaDll::find_children(uia_control(@locators[:id]), children)
|
48
|
+
target_element = children.read_array_of_pointer(length)[index]
|
49
|
+
|
50
|
+
UiaDll::select(target_element)
|
51
|
+
end
|
52
|
+
|
53
|
+
alias_method :strings, :items
|
54
|
+
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
@@ -13,7 +13,6 @@ module RAutomation
|
|
13
13
|
locators[:index] = locators[:index].to_i if locators[:index]
|
14
14
|
|
15
15
|
# control locator
|
16
|
-
locators[:id] = locators[:id].to_i if locators[:id]
|
17
16
|
locators = self.class::DEFAULT_LOCATORS.merge(locators) if self.class.const_defined?(:DEFAULT_LOCATORS)
|
18
17
|
@locators = locators
|
19
18
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module RAutomation
|
2
|
+
module Adapter
|
3
|
+
module WinFfi
|
4
|
+
# @private
|
5
|
+
module UiaDll
|
6
|
+
extend FFI::Library
|
7
|
+
|
8
|
+
ffi_lib File.dirname(__FILE__) + '/../../../../../ext/UiaDll/Release/UiaDll.dll'
|
9
|
+
ffi_convention :stdcall
|
10
|
+
|
11
|
+
attach_function :find_window, :RA_FindWindow,
|
12
|
+
[:string], :pointer
|
13
|
+
attach_function :is_offscreen, :RA_IsOffscreen,
|
14
|
+
[:pointer], :bool
|
15
|
+
attach_function :element_from_handle, :RA_ElementFromHandle,
|
16
|
+
[:long], :pointer
|
17
|
+
attach_function :find_child_by_id, :RA_FindChildById,
|
18
|
+
[:pointer, :string], :pointer
|
19
|
+
attach_function :current_native_window_handle, :RA_CurrentNativeWindowHandle,
|
20
|
+
[:pointer], :long
|
21
|
+
attach_function :set_focus, :RA_SetFocus,
|
22
|
+
[:pointer], :bool
|
23
|
+
attach_function :current_control_type, :RA_GetCurrentControlType,
|
24
|
+
[:pointer], :int
|
25
|
+
attach_function :find_children, :RA_FindChildren,
|
26
|
+
[:pointer, :pointer], :int
|
27
|
+
attach_function :get_name, :RA_GetName,
|
28
|
+
[:pointer, :pointer], :int
|
29
|
+
attach_function :get_is_selected, :RA_GetIsSelected,
|
30
|
+
[:pointer, :pointer], :int
|
31
|
+
attach_function :select, :RA_Select,
|
32
|
+
[:pointer], :int
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -9,21 +9,24 @@ module RAutomation
|
|
9
9
|
class SelectListOption
|
10
10
|
attr_accessor :text, :index, :control_hwnd
|
11
11
|
|
12
|
-
def initialize(
|
13
|
-
@
|
12
|
+
def initialize(select_list, text, index)
|
13
|
+
@select_list = select_list
|
14
14
|
@text = text
|
15
15
|
@index = index
|
16
16
|
end
|
17
17
|
|
18
18
|
def selected?
|
19
|
-
selected_idx = Functions.send_message(@control_hwnd, Constants::CB_GETCURSEL, 0, nil)
|
19
|
+
selected_idx = Functions.send_message(@select_list.control_hwnd, Constants::CB_GETCURSEL, 0, nil)
|
20
20
|
return false if selected_idx == Constants::CB_ERR
|
21
|
-
@text == Functions.retrieve_combobox_item_text(@control_hwnd, selected_idx)
|
21
|
+
@text == Functions.retrieve_combobox_item_text(@select_list.control_hwnd, selected_idx)
|
22
22
|
end
|
23
23
|
|
24
24
|
def select
|
25
|
-
|
25
|
+
@select_list.assert_enabled
|
26
|
+
Functions.send_message(@select_list.control_hwnd, Constants::CB_SETCURSEL, @index, nil) != Constants::CB_ERR
|
26
27
|
end
|
28
|
+
|
29
|
+
alias_method :set, :select
|
27
30
|
end
|
28
31
|
|
29
32
|
def initialize(window, locators)
|
@@ -38,9 +41,9 @@ module RAutomation
|
|
38
41
|
item = Functions.retrieve_combobox_item_text(@hwnd, item_no)
|
39
42
|
|
40
43
|
if options[:text]
|
41
|
-
items.push(SelectListOption.new(
|
44
|
+
items.push(SelectListOption.new(self, item, item_no)) if options[:text] == item
|
42
45
|
else
|
43
|
-
items.push(SelectListOption.new(
|
46
|
+
items.push(SelectListOption.new(self, item, item_no))
|
44
47
|
end
|
45
48
|
end
|
46
49
|
|
@@ -52,12 +55,32 @@ module RAutomation
|
|
52
55
|
selected_option ? selected_option.text : ""
|
53
56
|
end
|
54
57
|
|
58
|
+
def option(options)
|
59
|
+
item_count.times do |item_no|
|
60
|
+
item = Functions.retrieve_combobox_item_text(@hwnd, item_no)
|
61
|
+
return SelectListOption.new(self, item, item_no) if options[:text] == item
|
62
|
+
end
|
63
|
+
|
64
|
+
nil
|
65
|
+
end
|
66
|
+
|
67
|
+
def control_hwnd
|
68
|
+
@hwnd
|
69
|
+
end
|
70
|
+
|
71
|
+
def exist?
|
72
|
+
@locators[:id].nil? ? super : super && matches_type(Constants::UIA_COMBOBOX_CONTROL_TYPE)
|
73
|
+
end
|
74
|
+
|
75
|
+
alias_method :exists?, :exist?
|
76
|
+
|
55
77
|
private
|
56
78
|
|
57
79
|
def item_count
|
58
80
|
Functions.send_message(@hwnd, Constants::CB_GETCOUNT, 0, nil)
|
59
81
|
end
|
60
82
|
|
83
|
+
|
61
84
|
end
|
62
85
|
end
|
63
86
|
end
|