uia 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/UiaDll/UIA.Helper/Element.cs +21 -2
- data/ext/UiaDll/UIA.Helper/Extensions.cs +5 -0
- data/ext/UiaDll/UiaDll.Test/ElementInformationTest.cpp +4 -4
- data/ext/UiaDll/UiaDll.Test/ElementStub.h +3 -3
- data/ext/UiaDll/UiaDll/ElementMethods.cpp +2 -2
- data/ext/UiaDll/UiaDll/ElementStructures.h +5 -5
- data/lib/uia/version.rb +1 -1
- metadata +4 -4
@@ -1,5 +1,7 @@
|
|
1
1
|
using System;
|
2
|
+
using System.Collections.Generic;
|
2
3
|
using System.Linq;
|
4
|
+
using System.Runtime.InteropServices;
|
3
5
|
using System.Windows.Automation;
|
4
6
|
|
5
7
|
namespace UIA.Helper
|
@@ -8,11 +10,15 @@ namespace UIA.Helper
|
|
8
10
|
{
|
9
11
|
private readonly AutomationElement _element;
|
10
12
|
|
13
|
+
[DllImport("user32")]
|
14
|
+
[return: MarshalAs(UnmanagedType.Bool)]
|
15
|
+
static extern bool IsWindow(IntPtr hWnd);
|
16
|
+
|
11
17
|
protected Element()
|
12
18
|
{
|
13
19
|
}
|
14
20
|
|
15
|
-
|
21
|
+
protected Element(AutomationElement element)
|
16
22
|
{
|
17
23
|
_element = element;
|
18
24
|
}
|
@@ -179,7 +185,14 @@ namespace UIA.Helper
|
|
179
185
|
|
180
186
|
public static Element ByRuntimeId(int[] runtimeId)
|
181
187
|
{
|
182
|
-
|
188
|
+
var condition = new PropertyCondition(AutomationElement.RuntimeIdProperty, runtimeId);
|
189
|
+
return ClosestParentOfId(runtimeId).FindFirst(TreeScope.Subtree, condition);
|
190
|
+
}
|
191
|
+
|
192
|
+
private static Element ClosestParentOfId(IEnumerable<int> runtimeId)
|
193
|
+
{
|
194
|
+
var parentHandle = runtimeId.LastOrDefault(x => IsWindow(x.IntPtr())).IntPtr();
|
195
|
+
return IntPtr.Zero != parentHandle ? ByHandle(parentHandle) : new RootElement();
|
183
196
|
}
|
184
197
|
|
185
198
|
private static Element[] Find(AutomationElement element, TreeScope scope, Condition condition)
|
@@ -199,4 +212,10 @@ namespace UIA.Helper
|
|
199
212
|
return null == automationElement ? null : new Element(automationElement);
|
200
213
|
}
|
201
214
|
}
|
215
|
+
|
216
|
+
class RootElement : Element
|
217
|
+
{
|
218
|
+
public RootElement() : base(AutomationElement.RootElement)
|
219
|
+
{ }
|
220
|
+
}
|
202
221
|
}
|
@@ -21,6 +21,11 @@ namespace UIA.Helper
|
|
21
21
|
|
22
22
|
return new Point(rectangle.Left + rectangle.Width / 2, rectangle.Top + rectangle.Height / 2);
|
23
23
|
}
|
24
|
+
|
25
|
+
public static IntPtr IntPtr(this int value)
|
26
|
+
{
|
27
|
+
return new IntPtr(value);
|
28
|
+
}
|
24
29
|
}
|
25
30
|
|
26
31
|
public static class PropertyExtensions
|
@@ -59,7 +59,7 @@ TEST_F(ElementInformationTest, ItKnowsTheWindowHandle)
|
|
59
59
|
auto element = gcnew ElementStub("");
|
60
60
|
element->NativeWindowHandle = 12345;
|
61
61
|
|
62
|
-
ASSERT_EQ(ElementInformation(element).
|
62
|
+
ASSERT_EQ(ElementInformation(element).handle, 12345);
|
63
63
|
}
|
64
64
|
|
65
65
|
TEST_F(ElementInformationTest, ItKnowsTheControlType)
|
@@ -116,7 +116,7 @@ TEST_F(ElementInformationTest, ItCanBeRefreshed)
|
|
116
116
|
const int expectedId[] = {46, 2};
|
117
117
|
ASSERT_THAT(expectedId, ::testing::ElementsAreArray(elementInformation.runtimeId, elementInformation.runtimeIdLength));
|
118
118
|
ASSERT_STREQ("Refreshed", elementInformation.name);
|
119
|
-
ASSERT_EQ(123, elementInformation.
|
119
|
+
ASSERT_EQ(123, elementInformation.handle);
|
120
120
|
}
|
121
121
|
|
122
122
|
TEST_F(ElementInformationTest, ItCanBeInitializedFromManyElements) {
|
@@ -203,7 +203,7 @@ TEST(ElementInformation, ToString_HasName)
|
|
203
203
|
TEST(ElementInformation, ToString_HasHandle)
|
204
204
|
{
|
205
205
|
ElementInformation el;
|
206
|
-
el.
|
206
|
+
el.handle = 0x123;
|
207
207
|
ASSERT_EXPECTED_EL_TO_STRING("id: (null), name: (null), handle: 0x123, runtime_id: (null)");
|
208
208
|
}
|
209
209
|
|
@@ -221,7 +221,7 @@ TEST(ElementInformation, ToString_AllTheThings)
|
|
221
221
|
ElementInformation el;
|
222
222
|
el.name = StringHelper::ToUnmanaged("someName");
|
223
223
|
el.id = StringHelper::ToUnmanaged("someId");
|
224
|
-
el.
|
224
|
+
el.handle = 0xffff;
|
225
225
|
el.runtimeId = new int[1];
|
226
226
|
el.runtimeId[0] = 42789;
|
227
227
|
el.runtimeIdLength = 1;
|
@@ -73,8 +73,8 @@ public:
|
|
73
73
|
|
74
74
|
virtual property int NativeWindowHandle
|
75
75
|
{
|
76
|
-
int get() override { return
|
77
|
-
void set(int value) {
|
76
|
+
int get() override { return _handle; }
|
77
|
+
void set(int value) { _handle = value; }
|
78
78
|
}
|
79
79
|
|
80
80
|
virtual property int ControlTypeId
|
@@ -100,7 +100,7 @@ private:
|
|
100
100
|
String^ _id;
|
101
101
|
array<int>^ _runtimeIds;
|
102
102
|
array<int>^ _patterns;
|
103
|
-
int
|
103
|
+
int _handle;
|
104
104
|
int _controlTypeId;
|
105
105
|
bool _isEnabled;
|
106
106
|
bool _isVisible;
|
@@ -8,8 +8,8 @@ extern "C" {
|
|
8
8
|
Element^ foundElement = nullptr;
|
9
9
|
|
10
10
|
try {
|
11
|
-
if( element->
|
12
|
-
foundElement = Element::ByHandle(IntPtr(element->
|
11
|
+
if( element->handle > 0 ) {
|
12
|
+
foundElement = Element::ByHandle(IntPtr(element->handle));
|
13
13
|
} else {
|
14
14
|
foundElement = Element::ByRuntimeId(ArrayHelper::ToArray(element->runtimeId, element->runtimeIdLength));
|
15
15
|
}
|
@@ -4,7 +4,7 @@
|
|
4
4
|
#include <stdio.h>
|
5
5
|
|
6
6
|
typedef struct _ElementInformation {
|
7
|
-
int
|
7
|
+
int handle;
|
8
8
|
int* runtimeId;
|
9
9
|
int runtimeIdLength;
|
10
10
|
char* name;
|
@@ -20,9 +20,9 @@ typedef struct _ElementInformation {
|
|
20
20
|
bool hasKeyboardFocus;
|
21
21
|
long boundingRectangle[4];
|
22
22
|
|
23
|
-
_ElementInformation() : name(NULL),
|
23
|
+
_ElementInformation() : name(NULL), handle(0), runtimeId(NULL), patterns(NULL), id(NULL), className(NULL), helpText(NULL) {}
|
24
24
|
|
25
|
-
_ElementInformation(Element^ element) : name(NULL),
|
25
|
+
_ElementInformation(Element^ element) : name(NULL), handle(0), runtimeId(NULL), patterns(NULL), id(NULL), className(NULL), helpText(NULL) {
|
26
26
|
Refresh(element);
|
27
27
|
}
|
28
28
|
|
@@ -55,7 +55,7 @@ typedef struct _ElementInformation {
|
|
55
55
|
id = StringHelper::ToUnmanaged(element->Id);
|
56
56
|
name = StringHelper::ToUnmanaged(element->Name);
|
57
57
|
className = StringHelper::ToUnmanaged(element->ClassName);
|
58
|
-
|
58
|
+
handle = element->NativeWindowHandle;
|
59
59
|
runtimeId = ArrayHelper::FromArray(element->RuntimeId);
|
60
60
|
runtimeIdLength = element->RuntimeId->Length;
|
61
61
|
controlTypeId = element->ControlTypeId;
|
@@ -81,7 +81,7 @@ typedef struct _ElementInformation {
|
|
81
81
|
const int ToString(char* s, const int length) {
|
82
82
|
const char* format = "id: %s, name: %s, handle: 0x%x, runtime_id: %s";
|
83
83
|
auto runtimeIdString = RuntimeIdString();
|
84
|
-
auto neededLength = _snprintf(s, length, format, id, name,
|
84
|
+
auto neededLength = _snprintf(s, length, format, id, name, handle, runtimeIdString) + 1;
|
85
85
|
delete[] runtimeIdString;
|
86
86
|
return neededLength;
|
87
87
|
}
|
data/lib/uia/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-05-
|
12
|
+
date: 2014-05-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
@@ -262,7 +262,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
262
262
|
version: '0'
|
263
263
|
segments:
|
264
264
|
- 0
|
265
|
-
hash:
|
265
|
+
hash: 795502381
|
266
266
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
267
267
|
none: false
|
268
268
|
requirements:
|
@@ -271,7 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
271
271
|
version: '0'
|
272
272
|
segments:
|
273
273
|
- 0
|
274
|
-
hash:
|
274
|
+
hash: 795502381
|
275
275
|
requirements: []
|
276
276
|
rubyforge_project:
|
277
277
|
rubygems_version: 1.8.28
|