rautomation 2.0.1-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.gitignore +41 -0
- data/.rspec +2 -0
- data/.yardopts +8 -0
- data/CHANGES.md +276 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +142 -0
- data/Rakefile +73 -0
- data/ext/AutoItX/AutoItX.chm +0 -0
- data/ext/AutoItX/AutoItX3.dll +0 -0
- data/ext/IAccessibleDLL/IAccessibleDLL/IAccessibleDLL.cpp +30 -0
- data/ext/IAccessibleDLL/IAccessibleDLL/IAccessibleDLL.vcxproj +179 -0
- data/ext/IAccessibleDLL/IAccessibleDLL/IAccessibleDLL.vcxproj.filters +42 -0
- data/ext/IAccessibleDLL/IAccessibleDLL/IAccessibleDLL.vcxproj.user +3 -0
- data/ext/IAccessibleDLL/IAccessibleDLL/ReadMe.txt +48 -0
- data/ext/IAccessibleDLL/IAccessibleDLL/dllmain.cpp +19 -0
- data/ext/IAccessibleDLL/IAccessibleDLL/stdafx.cpp +8 -0
- data/ext/IAccessibleDLL/IAccessibleDLL/stdafx.h +22 -0
- data/ext/IAccessibleDLL/IAccessibleDLL/table_support.cpp +282 -0
- data/ext/IAccessibleDLL/IAccessibleDLL/targetver.h +8 -0
- data/ext/IAccessibleDLL/IAccessibleDLL.sln +31 -0
- data/ext/IAccessibleDLL/IAccessibleDLL.suo +0 -0
- data/ext/IAccessibleDLL/Release/IAccessibleDLL.dll +0 -0
- data/ext/UiaDll/RAutomation.UIA/Controls/Clicker.cs +63 -0
- data/ext/UiaDll/RAutomation.UIA/Controls/SelectList.cs +116 -0
- data/ext/UiaDll/RAutomation.UIA/Controls/Spinner.cs +46 -0
- data/ext/UiaDll/RAutomation.UIA/Controls/TabControl.cs +54 -0
- data/ext/UiaDll/RAutomation.UIA/Controls/TableControl.cs +132 -0
- data/ext/UiaDll/RAutomation.UIA/Controls/TextControl.cs +50 -0
- data/ext/UiaDll/RAutomation.UIA/Expander.cs +59 -0
- data/ext/UiaDll/RAutomation.UIA/Extensions/Element.cs +166 -0
- data/ext/UiaDll/RAutomation.UIA/Extensions/Enumerable.cs +76 -0
- data/ext/UiaDll/RAutomation.UIA/Extensions/Property.cs +27 -0
- data/ext/UiaDll/RAutomation.UIA/Properties/AssemblyInfo.cs +36 -0
- data/ext/UiaDll/RAutomation.UIA/Properties/AutomationProperties.cs +18 -0
- data/ext/UiaDll/RAutomation.UIA/RAutomation.UIA.csproj +77 -0
- data/ext/UiaDll/Release/RAutomation.UIA.dll +0 -0
- data/ext/UiaDll/Release/UiaDll.dll +0 -0
- data/ext/UiaDll/UiaDll/ArrayHelper.cpp +14 -0
- data/ext/UiaDll/UiaDll/ArrayHelper.h +7 -0
- data/ext/UiaDll/UiaDll/AssemblyInfo.cpp +40 -0
- data/ext/UiaDll/UiaDll/ControlMethods.cpp +16 -0
- data/ext/UiaDll/UiaDll/DynamicAssemblyResolver.cpp +24 -0
- data/ext/UiaDll/UiaDll/DynamicAssemblyResolver.h +16 -0
- data/ext/UiaDll/UiaDll/Locator.cpp +93 -0
- data/ext/UiaDll/UiaDll/Locator.h +55 -0
- data/ext/UiaDll/UiaDll/MenuItemSelector.cpp +75 -0
- data/ext/UiaDll/UiaDll/MenuItemSelector.h +24 -0
- data/ext/UiaDll/UiaDll/MenuMethods.cpp +62 -0
- data/ext/UiaDll/UiaDll/ReadMe.txt +38 -0
- data/ext/UiaDll/UiaDll/SelectListMethods.cpp +84 -0
- data/ext/UiaDll/UiaDll/SpinnerMethods.cpp +61 -0
- data/ext/UiaDll/UiaDll/StringHelper.cpp +57 -0
- data/ext/UiaDll/UiaDll/StringHelper.h +15 -0
- data/ext/UiaDll/UiaDll/StringMethods.cpp +8 -0
- data/ext/UiaDll/UiaDll/TabControlMethods.cpp +40 -0
- data/ext/UiaDll/UiaDll/TableMethods.cpp +108 -0
- data/ext/UiaDll/UiaDll/TextMethods.cpp +25 -0
- data/ext/UiaDll/UiaDll/ToggleStateHelper.h +10 -0
- data/ext/UiaDll/UiaDll/UiaDll.cpp +216 -0
- data/ext/UiaDll/UiaDll/UiaDll.h +13 -0
- data/ext/UiaDll/UiaDll/UiaDll.vcxproj +167 -0
- data/ext/UiaDll/UiaDll/UiaDll.vcxproj.filters +110 -0
- data/ext/UiaDll/UiaDll/app.ico +0 -0
- data/ext/UiaDll/UiaDll/app.rc +0 -0
- data/ext/UiaDll/UiaDll/dllmain.cpp +1 -0
- data/ext/UiaDll/UiaDll/resource.h +3 -0
- data/ext/UiaDll/UiaDll/stdafx.cpp +5 -0
- data/ext/UiaDll/UiaDll/stdafx.h +41 -0
- data/ext/UiaDll/UiaDll/targetver.h +8 -0
- data/ext/UiaDll/UiaDll.sln +57 -0
- data/ext/WindowsForms/.nuget/NuGet.Config +6 -0
- data/ext/WindowsForms/.nuget/NuGet.exe +0 -0
- data/ext/WindowsForms/.nuget/NuGet.targets +136 -0
- data/ext/WindowsForms/Release/FizzWare.NBuilder.dll +0 -0
- data/ext/WindowsForms/Release/UIA.Extensions.dll +0 -0
- data/ext/WindowsForms/Release/WindowsForms.exe +0 -0
- data/ext/WindowsForms/WindowsForms/AboutBox.Designer.cs +168 -0
- data/ext/WindowsForms/WindowsForms/AboutBox.cs +103 -0
- data/ext/WindowsForms/WindowsForms/AboutBox.resx +123 -0
- data/ext/WindowsForms/WindowsForms/DataEntryForm.Designer.cs +218 -0
- data/ext/WindowsForms/WindowsForms/DataEntryForm.cs +52 -0
- data/ext/WindowsForms/WindowsForms/DataEntryForm.resx +120 -0
- data/ext/WindowsForms/WindowsForms/DataGridView.Designer.cs +77 -0
- data/ext/WindowsForms/WindowsForms/DataGridView.cs +43 -0
- data/ext/WindowsForms/WindowsForms/DataGridView.resx +120 -0
- data/ext/WindowsForms/WindowsForms/FizzWare.NBuilder.dll +0 -0
- data/ext/WindowsForms/WindowsForms/MainFormWindow.Designer.cs +527 -0
- data/ext/WindowsForms/WindowsForms/MainFormWindow.cs +109 -0
- data/ext/WindowsForms/WindowsForms/MainFormWindow.resx +126 -0
- data/ext/WindowsForms/WindowsForms/PersonForm.Designer.cs +119 -0
- data/ext/WindowsForms/WindowsForms/PersonForm.cs +34 -0
- data/ext/WindowsForms/WindowsForms/PersonForm.resx +120 -0
- data/ext/WindowsForms/WindowsForms/Program.cs +21 -0
- data/ext/WindowsForms/WindowsForms/Properties/AssemblyInfo.cs +36 -0
- data/ext/WindowsForms/WindowsForms/Properties/Resources.Designer.cs +71 -0
- data/ext/WindowsForms/WindowsForms/Properties/Resources.resx +117 -0
- data/ext/WindowsForms/WindowsForms/Properties/Settings.Designer.cs +30 -0
- data/ext/WindowsForms/WindowsForms/Properties/Settings.settings +7 -0
- data/ext/WindowsForms/WindowsForms/SimpleElementsForm.Designer.cs +93 -0
- data/ext/WindowsForms/WindowsForms/SimpleElementsForm.cs +19 -0
- data/ext/WindowsForms/WindowsForms/SimpleElementsForm.resx +120 -0
- data/ext/WindowsForms/WindowsForms/UIA.Extensions.dll +0 -0
- data/ext/WindowsForms/WindowsForms/ValueMonthCalendar.cs +28 -0
- data/ext/WindowsForms/WindowsForms/WindowsForms.csproj +166 -0
- data/ext/WindowsForms/WindowsForms/packages.config +4 -0
- data/ext/WindowsForms/WindowsForms.sln +46 -0
- data/lib/rautomation/adapter/autoit/button.rb +59 -0
- data/lib/rautomation/adapter/autoit/locators.rb +22 -0
- data/lib/rautomation/adapter/autoit/mouse.rb +38 -0
- data/lib/rautomation/adapter/autoit/text_field.rb +70 -0
- data/lib/rautomation/adapter/autoit/window.rb +197 -0
- data/lib/rautomation/adapter/autoit.rb +8 -0
- data/lib/rautomation/adapter/helper.rb +64 -0
- data/lib/rautomation/adapter/ms_uia/button.rb +21 -0
- data/lib/rautomation/adapter/ms_uia/button_helper.rb +19 -0
- data/lib/rautomation/adapter/ms_uia/checkbox.rb +23 -0
- data/lib/rautomation/adapter/ms_uia/constants.rb +111 -0
- data/lib/rautomation/adapter/ms_uia/control.rb +134 -0
- data/lib/rautomation/adapter/ms_uia/functions.rb +279 -0
- data/lib/rautomation/adapter/ms_uia/keys.rb +121 -0
- data/lib/rautomation/adapter/ms_uia/keystroke_converter.rb +122 -0
- data/lib/rautomation/adapter/ms_uia/label.rb +18 -0
- data/lib/rautomation/adapter/ms_uia/list_box.rb +46 -0
- data/lib/rautomation/adapter/ms_uia/list_item.rb +22 -0
- data/lib/rautomation/adapter/ms_uia/locators.rb +23 -0
- data/lib/rautomation/adapter/ms_uia/menu.rb +36 -0
- data/lib/rautomation/adapter/ms_uia/radio.rb +23 -0
- data/lib/rautomation/adapter/ms_uia/select_list.rb +85 -0
- data/lib/rautomation/adapter/ms_uia/spinner.rb +31 -0
- data/lib/rautomation/adapter/ms_uia/tab_control.rb +46 -0
- data/lib/rautomation/adapter/ms_uia/table.rb +140 -0
- data/lib/rautomation/adapter/ms_uia/text_field.rb +39 -0
- data/lib/rautomation/adapter/ms_uia/uia_dll.rb +428 -0
- data/lib/rautomation/adapter/ms_uia/value_control.rb +21 -0
- data/lib/rautomation/adapter/ms_uia/window.rb +289 -0
- data/lib/rautomation/adapter/ms_uia.rb +27 -0
- data/lib/rautomation/adapter/win_32/button.rb +14 -0
- data/lib/rautomation/adapter/win_32/button_helper.rb +24 -0
- data/lib/rautomation/adapter/win_32/checkbox.rb +14 -0
- data/lib/rautomation/adapter/win_32/constants.rb +73 -0
- data/lib/rautomation/adapter/win_32/control.rb +86 -0
- data/lib/rautomation/adapter/win_32/functions.rb +336 -0
- data/lib/rautomation/adapter/win_32/keys.rb +146 -0
- data/lib/rautomation/adapter/win_32/label.rb +10 -0
- data/lib/rautomation/adapter/win_32/list_box.rb +40 -0
- data/lib/rautomation/adapter/win_32/locators.rb +22 -0
- data/lib/rautomation/adapter/win_32/mouse.rb +59 -0
- data/lib/rautomation/adapter/win_32/password_field.rb +15 -0
- data/lib/rautomation/adapter/win_32/radio.rb +11 -0
- data/lib/rautomation/adapter/win_32/select_list.rb +97 -0
- data/lib/rautomation/adapter/win_32/table.rb +25 -0
- data/lib/rautomation/adapter/win_32/text_field.rb +52 -0
- data/lib/rautomation/adapter/win_32/window.rb +277 -0
- data/lib/rautomation/adapter/win_32.rb +23 -0
- data/lib/rautomation/button.rb +55 -0
- data/lib/rautomation/element_collections.rb +55 -0
- data/lib/rautomation/platform.rb +15 -0
- data/lib/rautomation/text_field.rb +60 -0
- data/lib/rautomation/version.rb +3 -0
- data/lib/rautomation/wait_helper.rb +23 -0
- data/lib/rautomation/window.rb +248 -0
- data/lib/rautomation.rb +8 -0
- data/rautomation.gemspec +52 -0
- data/spec/adapter/autoit/mouse_spec.rb +53 -0
- data/spec/adapter/autoit/window_spec.rb +17 -0
- data/spec/adapter/ms_uia/button_spec.rb +39 -0
- data/spec/adapter/ms_uia/checkbox_spec.rb +55 -0
- data/spec/adapter/ms_uia/control_spec.rb +88 -0
- data/spec/adapter/ms_uia/functions_spec.rb +39 -0
- data/spec/adapter/ms_uia/keystroke_converter_spec.rb +48 -0
- data/spec/adapter/ms_uia/label_spec.rb +18 -0
- data/spec/adapter/ms_uia/list_item_spec.rb +14 -0
- data/spec/adapter/ms_uia/listbox_spec.rb +73 -0
- data/spec/adapter/ms_uia/radio_spec.rb +39 -0
- data/spec/adapter/ms_uia/select_list_spec.rb +118 -0
- data/spec/adapter/ms_uia/spinner_spec.rb +44 -0
- data/spec/adapter/ms_uia/tab_control_spec.rb +53 -0
- data/spec/adapter/ms_uia/table_spec.rb +197 -0
- data/spec/adapter/ms_uia/text_field_spec.rb +43 -0
- data/spec/adapter/ms_uia/value_control_spec.rb +11 -0
- data/spec/adapter/ms_uia/window_spec.rb +81 -0
- data/spec/adapter/win_32/button_spec.rb +31 -0
- data/spec/adapter/win_32/checkbox_spec.rb +46 -0
- data/spec/adapter/win_32/label_spec.rb +13 -0
- data/spec/adapter/win_32/listbox_spec.rb +41 -0
- data/spec/adapter/win_32/mouse_spec.rb +49 -0
- data/spec/adapter/win_32/radio_spec.rb +33 -0
- data/spec/adapter/win_32/select_list_spec.rb +65 -0
- data/spec/adapter/win_32/table_spec.rb +27 -0
- data/spec/adapter/win_32/text_field_spec.rb +24 -0
- data/spec/adapter/win_32/window_spec.rb +61 -0
- data/spec/button_spec.rb +67 -0
- data/spec/buttons_spec.rb +21 -0
- data/spec/spec_helper.rb +128 -0
- data/spec/text_field_spec.rb +64 -0
- data/spec/text_fields_spec.rb +22 -0
- data/spec/window_spec.rb +150 -0
- data/spec/windows_spec.rb +76 -0
- metadata +369 -0
@@ -0,0 +1,63 @@
|
|
1
|
+
using System;
|
2
|
+
using System.Runtime.InteropServices;
|
3
|
+
using System.Threading;
|
4
|
+
using System.Windows;
|
5
|
+
using System.Windows.Automation;
|
6
|
+
using System.Windows.Forms;
|
7
|
+
using RAutomation.UIA.Extensions;
|
8
|
+
|
9
|
+
namespace RAutomation.UIA.Controls
|
10
|
+
{
|
11
|
+
public class Clicker
|
12
|
+
{
|
13
|
+
[DllImport("user32.dll")]
|
14
|
+
static extern void mouse_event(uint flags, uint x, uint y, uint data, int extraInfo);
|
15
|
+
|
16
|
+
[Flags]
|
17
|
+
public enum MouseEvent
|
18
|
+
{
|
19
|
+
Leftdown = 0x00000002,
|
20
|
+
Leftup = 0x00000004,
|
21
|
+
}
|
22
|
+
|
23
|
+
private const uint MOUSEEVENTLF_LEFTDOWN = 0x2;
|
24
|
+
private const uint MOUSEEVENTLF_LEFTUP = 0x4;
|
25
|
+
|
26
|
+
public static bool Click(AutomationElement element)
|
27
|
+
{
|
28
|
+
try
|
29
|
+
{
|
30
|
+
if (AutomationElement.IsInvokePatternAvailableProperty.In(element))
|
31
|
+
{
|
32
|
+
element.As<InvokePattern>(InvokePattern.Pattern).Invoke();
|
33
|
+
}
|
34
|
+
else if (AutomationElement.IsTogglePatternAvailableProperty.In(element))
|
35
|
+
{
|
36
|
+
element.AsTogglePattern().Toggle();
|
37
|
+
}
|
38
|
+
else if (AutomationElement.IsSelectionItemPatternAvailableProperty.In(element))
|
39
|
+
{
|
40
|
+
element.AsSelectionItem().Select();
|
41
|
+
}
|
42
|
+
|
43
|
+
return true;
|
44
|
+
}
|
45
|
+
catch (Exception e)
|
46
|
+
{
|
47
|
+
Console.WriteLine(e);
|
48
|
+
return false;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
public static void MouseClick(AutomationElement element)
|
53
|
+
{
|
54
|
+
element.ScrollToIfPossible();
|
55
|
+
element.SetFocus();
|
56
|
+
|
57
|
+
var clickablePoint = element.GetClickablePoint();
|
58
|
+
Cursor.Position = new System.Drawing.Point((int)clickablePoint.X, (int)clickablePoint.Y);
|
59
|
+
mouse_event(MOUSEEVENTLF_LEFTDOWN, 0, 0, 0, 0);
|
60
|
+
mouse_event(MOUSEEVENTLF_LEFTUP, 0, 0, 0, 0);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
@@ -0,0 +1,116 @@
|
|
1
|
+
using System.Collections.Generic;
|
2
|
+
using System.Linq;
|
3
|
+
using System.Threading;
|
4
|
+
using System.Windows;
|
5
|
+
using System.Windows.Automation;
|
6
|
+
using RAutomation.UIA.Extensions;
|
7
|
+
using RAutomation.UIA.Properties;
|
8
|
+
|
9
|
+
namespace RAutomation.UIA.Controls
|
10
|
+
{
|
11
|
+
public class SelectList
|
12
|
+
{
|
13
|
+
private readonly AutomationElement _element;
|
14
|
+
|
15
|
+
public SelectList(AutomationElement element)
|
16
|
+
{
|
17
|
+
_element = element;
|
18
|
+
}
|
19
|
+
|
20
|
+
public string[] Options
|
21
|
+
{
|
22
|
+
get { return SelectionItems.Names().ToArray(); }
|
23
|
+
}
|
24
|
+
|
25
|
+
public int Count
|
26
|
+
{
|
27
|
+
get { return SelectionItems.Count(); }
|
28
|
+
}
|
29
|
+
|
30
|
+
public int SelectedIndex
|
31
|
+
{
|
32
|
+
get { return SelectionItems.IndexOf(IsSelected); }
|
33
|
+
set { Select(SelectionItems.ElementAt(value)); }
|
34
|
+
}
|
35
|
+
|
36
|
+
public string At(int index)
|
37
|
+
{
|
38
|
+
return SelectionItems.ElementAt(index).Current.Name;
|
39
|
+
}
|
40
|
+
|
41
|
+
public string Selection
|
42
|
+
{
|
43
|
+
get
|
44
|
+
{
|
45
|
+
var selection = SelectionItems.FirstOrDefault(IsSelected);
|
46
|
+
return null == selection ? "" : selection.Current.Name;
|
47
|
+
}
|
48
|
+
set
|
49
|
+
{
|
50
|
+
Select(SelectionItems.First(x => x.Current.Name == value));
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
public string[] Selections
|
55
|
+
{
|
56
|
+
get { return SelectionPattern.GetSelection().Select(x => x.Current.Name).ToArray(); }
|
57
|
+
}
|
58
|
+
|
59
|
+
public void Remove(int index)
|
60
|
+
{
|
61
|
+
SelectionItems.ElementAt(index).AsSelectionItem().RemoveFromSelection();
|
62
|
+
}
|
63
|
+
|
64
|
+
public void Remove(string value)
|
65
|
+
{
|
66
|
+
SelectionNamed(value).RemoveFromSelection();
|
67
|
+
}
|
68
|
+
|
69
|
+
private void Select(AutomationElement element)
|
70
|
+
{
|
71
|
+
if (SelectionPattern.CanSelectMultiple)
|
72
|
+
MultipleSelect(element);
|
73
|
+
else
|
74
|
+
SingleSelect(element);
|
75
|
+
}
|
76
|
+
|
77
|
+
private static void MultipleSelect(AutomationElement element)
|
78
|
+
{
|
79
|
+
element.AsSelectionItem().AddToSelection();
|
80
|
+
}
|
81
|
+
|
82
|
+
private static void SingleSelect(AutomationElement element)
|
83
|
+
{
|
84
|
+
var selectionItem = element.AsSelectionItem();
|
85
|
+
|
86
|
+
try
|
87
|
+
{
|
88
|
+
Clicker.MouseClick(element);
|
89
|
+
}
|
90
|
+
catch { }
|
91
|
+
|
92
|
+
if (!selectionItem.Current.IsSelected)
|
93
|
+
selectionItem.Select();
|
94
|
+
}
|
95
|
+
|
96
|
+
private SelectionPattern.SelectionPatternInformation SelectionPattern
|
97
|
+
{
|
98
|
+
get { return _element.As<SelectionPattern>(System.Windows.Automation.SelectionPattern.Pattern).Current; }
|
99
|
+
}
|
100
|
+
|
101
|
+
private SelectionItemPattern SelectionNamed(string value)
|
102
|
+
{
|
103
|
+
return SelectionItems.First(x => x.Current.Name == value).AsSelectionItem();
|
104
|
+
}
|
105
|
+
|
106
|
+
private static bool IsSelected(AutomationElement element)
|
107
|
+
{
|
108
|
+
return element.AsSelectionItem().Current.IsSelected;
|
109
|
+
}
|
110
|
+
|
111
|
+
private IEnumerable<AutomationElement> SelectionItems
|
112
|
+
{
|
113
|
+
get { return _element.Find(AutomationProperties.IsSelectionItem); }
|
114
|
+
}
|
115
|
+
}
|
116
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
using System.Windows.Automation;
|
2
|
+
using RAutomation.UIA.Extensions;
|
3
|
+
|
4
|
+
namespace RAutomation.UIA.Controls
|
5
|
+
{
|
6
|
+
public class Spinner
|
7
|
+
{
|
8
|
+
private readonly AutomationElement _element;
|
9
|
+
|
10
|
+
public Spinner(AutomationElement element)
|
11
|
+
{
|
12
|
+
_element = element;
|
13
|
+
}
|
14
|
+
|
15
|
+
public double Value
|
16
|
+
{
|
17
|
+
get { return RangeValue.Current.Value; }
|
18
|
+
set { RangeValue.SetValue(value); }
|
19
|
+
}
|
20
|
+
|
21
|
+
public double Minimum
|
22
|
+
{
|
23
|
+
get { return RangeValue.Current.Minimum; }
|
24
|
+
}
|
25
|
+
|
26
|
+
public double Maximum
|
27
|
+
{
|
28
|
+
get { return RangeValue.Current.Maximum; }
|
29
|
+
}
|
30
|
+
|
31
|
+
public double Increment()
|
32
|
+
{
|
33
|
+
return Value += RangeValue.Current.SmallChange;
|
34
|
+
}
|
35
|
+
|
36
|
+
public double Decrement()
|
37
|
+
{
|
38
|
+
return Value -= RangeValue.Current.SmallChange;
|
39
|
+
}
|
40
|
+
|
41
|
+
private RangeValuePattern RangeValue
|
42
|
+
{
|
43
|
+
get { return _element.As<RangeValuePattern>(RangeValuePattern.Pattern); }
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
using System.Collections.Generic;
|
2
|
+
using System.Linq;
|
3
|
+
using System.Windows.Automation;
|
4
|
+
using RAutomation.UIA.Extensions;
|
5
|
+
|
6
|
+
namespace RAutomation.UIA.Controls
|
7
|
+
{
|
8
|
+
public class TabControl
|
9
|
+
{
|
10
|
+
private readonly AutomationElement _element;
|
11
|
+
|
12
|
+
public TabControl(AutomationElement element)
|
13
|
+
{
|
14
|
+
_element = element;
|
15
|
+
}
|
16
|
+
|
17
|
+
public string[] TabNames
|
18
|
+
{
|
19
|
+
get { return TabItems.Select(x => x.Current.Name).ToArray(); }
|
20
|
+
}
|
21
|
+
|
22
|
+
public string Selection
|
23
|
+
{
|
24
|
+
get { return TabItems.First(IsSelected).Current.Name; }
|
25
|
+
set { TabItems.First(x => x.Current.Name == value).AsSelectionItem().Select(); }
|
26
|
+
}
|
27
|
+
|
28
|
+
public int SelectedIndex
|
29
|
+
{
|
30
|
+
get { return TabItems.IndexOf(IsSelected); }
|
31
|
+
set { SelectionItems.ElementAt(value).Select(); }
|
32
|
+
}
|
33
|
+
|
34
|
+
private static bool IsSelected(AutomationElement tabItem)
|
35
|
+
{
|
36
|
+
return tabItem.AsSelectionItem().Current.IsSelected;
|
37
|
+
}
|
38
|
+
|
39
|
+
private IEnumerable<AutomationElement> TabItems
|
40
|
+
{
|
41
|
+
get { return _element.Find(IsTabItem); }
|
42
|
+
}
|
43
|
+
|
44
|
+
private IEnumerable<SelectionItemPattern> SelectionItems
|
45
|
+
{
|
46
|
+
get { return TabItems.AsSelectionItems(); }
|
47
|
+
}
|
48
|
+
|
49
|
+
private static Condition IsTabItem
|
50
|
+
{
|
51
|
+
get { return new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem); }
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
@@ -0,0 +1,132 @@
|
|
1
|
+
using System.Collections.Generic;
|
2
|
+
using System.Linq;
|
3
|
+
using System.Windows.Automation;
|
4
|
+
using RAutomation.UIA.Extensions;
|
5
|
+
using RAutomation.UIA.Properties;
|
6
|
+
|
7
|
+
namespace RAutomation.UIA.Controls
|
8
|
+
{
|
9
|
+
public class TableControl
|
10
|
+
{
|
11
|
+
private readonly AutomationElement _element;
|
12
|
+
|
13
|
+
public TableControl(AutomationElement element)
|
14
|
+
{
|
15
|
+
_element = element;
|
16
|
+
}
|
17
|
+
|
18
|
+
public int RowCount
|
19
|
+
{
|
20
|
+
get { return _element.As<TablePattern>(TablePattern.Pattern).Current.RowCount; }
|
21
|
+
}
|
22
|
+
|
23
|
+
public int SelectedIndex
|
24
|
+
{
|
25
|
+
get { return SelectionItems.IndexOf(x => x.Current.IsSelected); }
|
26
|
+
set { Select(value); }
|
27
|
+
}
|
28
|
+
|
29
|
+
public int[] SelectedIndexes
|
30
|
+
{
|
31
|
+
get { return DataItems.IndexesOf(x => x.AsSelectionItem().Current.IsSelected); }
|
32
|
+
}
|
33
|
+
|
34
|
+
public bool IsRowSelected(int dataItemIndex)
|
35
|
+
{
|
36
|
+
return DataItems.ElementAt(dataItemIndex).AsSelectionItem().Current.IsSelected;
|
37
|
+
}
|
38
|
+
|
39
|
+
public void Remove(int dataItemIndex)
|
40
|
+
{
|
41
|
+
DataItems.ElementAt(dataItemIndex).AsSelectionItem().RemoveFromSelection();
|
42
|
+
}
|
43
|
+
|
44
|
+
public void Remove(string dataItemValue)
|
45
|
+
{
|
46
|
+
DataItems.FirstOrDefault(x => x.Current.Name == dataItemValue).AsSelectionItem().RemoveFromSelection();
|
47
|
+
}
|
48
|
+
|
49
|
+
public string Value
|
50
|
+
{
|
51
|
+
set { Select(value); }
|
52
|
+
}
|
53
|
+
|
54
|
+
public bool Exists(int row, int column)
|
55
|
+
{
|
56
|
+
return At(row, column).Exists();
|
57
|
+
}
|
58
|
+
|
59
|
+
public string ValueAt(int row, int column)
|
60
|
+
{
|
61
|
+
return At(row, column).Current.Name;
|
62
|
+
}
|
63
|
+
|
64
|
+
public AutomationElement At(int row, int column)
|
65
|
+
{
|
66
|
+
return _element.FindOne(IsTableItem, GridItemPattern.ColumnProperty.Is(column), GridItemPattern.RowProperty.Is(row));
|
67
|
+
}
|
68
|
+
|
69
|
+
public string[] Headers
|
70
|
+
{
|
71
|
+
get { return _element.Find(ControlType.HeaderItem.Condition()).Select(x => x.Current.Name).ToArray(); }
|
72
|
+
}
|
73
|
+
|
74
|
+
public string[] Values
|
75
|
+
{
|
76
|
+
get { return TableOrListItems.Select(x => x.Current.Name).ToArray(); }
|
77
|
+
}
|
78
|
+
|
79
|
+
public void SingleSelect(int value)
|
80
|
+
{
|
81
|
+
DataItems.ElementAt(value).AsSelectionItem().Select();
|
82
|
+
}
|
83
|
+
|
84
|
+
private void Select(int value)
|
85
|
+
{
|
86
|
+
var selectionItem = DataItems.ElementAt(value).AsSelectionItem();
|
87
|
+
|
88
|
+
if (SelectionPattern.CanSelectMultiple)
|
89
|
+
selectionItem.AddToSelection();
|
90
|
+
else
|
91
|
+
selectionItem.Select();
|
92
|
+
}
|
93
|
+
|
94
|
+
private SelectionPattern.SelectionPatternInformation SelectionPattern
|
95
|
+
{
|
96
|
+
get { return _element.As<SelectionPattern>(SelectionPatternIdentifiers.Pattern).Current; }
|
97
|
+
}
|
98
|
+
|
99
|
+
private void Select(string value)
|
100
|
+
{
|
101
|
+
SelectionElements.First(x => x.Current.Name == value).AsSelectionItem().Select();
|
102
|
+
}
|
103
|
+
|
104
|
+
private IEnumerable<SelectionItemPattern> SelectionItems
|
105
|
+
{
|
106
|
+
get { return SelectionElements.Select(x => x.As<SelectionItemPattern>(SelectionItemPattern.Pattern)); }
|
107
|
+
}
|
108
|
+
|
109
|
+
private IEnumerable<AutomationElement> DataItems
|
110
|
+
{
|
111
|
+
get
|
112
|
+
{
|
113
|
+
return _element.Find(AutomationProperties.IsDataItem);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
private IEnumerable<AutomationElement> SelectionElements
|
118
|
+
{
|
119
|
+
get { return _element.Find(AutomationProperties.IsSelectionItem); }
|
120
|
+
}
|
121
|
+
|
122
|
+
private IEnumerable<AutomationElement> TableOrListItems
|
123
|
+
{
|
124
|
+
get { return _element.FindAny(IsTableItem, ControlType.ListItem.Condition()); }
|
125
|
+
}
|
126
|
+
|
127
|
+
private static Condition IsTableItem
|
128
|
+
{
|
129
|
+
get { return AutomationElement.IsTableItemPatternAvailableProperty.TrueCondition(); }
|
130
|
+
}
|
131
|
+
}
|
132
|
+
}
|
@@ -0,0 +1,50 @@
|
|
1
|
+
using System.Runtime.Remoting.Services;
|
2
|
+
using System.Windows.Automation;
|
3
|
+
using System.Windows.Forms;
|
4
|
+
using RAutomation.UIA.Extensions;
|
5
|
+
|
6
|
+
namespace RAutomation.UIA.Controls
|
7
|
+
{
|
8
|
+
public class TextControl
|
9
|
+
{
|
10
|
+
private readonly AutomationElement _element;
|
11
|
+
|
12
|
+
public TextControl(AutomationElement element)
|
13
|
+
{
|
14
|
+
_element = element;
|
15
|
+
}
|
16
|
+
|
17
|
+
public string Value
|
18
|
+
{
|
19
|
+
get { return _element.IsValuePattern() ? TextValue : DocumentText; }
|
20
|
+
set
|
21
|
+
{
|
22
|
+
if (_element.IsValuePattern())
|
23
|
+
TextValue = value;
|
24
|
+
else
|
25
|
+
DocumentText = value;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
private string DocumentText
|
30
|
+
{
|
31
|
+
get { return _element.AsTextPattern().DocumentRange.GetText(-1); }
|
32
|
+
set
|
33
|
+
{
|
34
|
+
_element.SetFocus();
|
35
|
+
Enter("^{HOME}", "^+{END}", "{DEL}", value);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
private static void Enter(params string[] keys)
|
40
|
+
{
|
41
|
+
keys.ForEach(SendKeys.SendWait);
|
42
|
+
}
|
43
|
+
|
44
|
+
private string TextValue
|
45
|
+
{
|
46
|
+
get { return _element.AsValuePattern().Current.Value; }
|
47
|
+
set { _element.AsValuePattern().SetValue(value); }
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
using System.Collections.Generic;
|
2
|
+
using System.Linq;
|
3
|
+
using System.Windows.Automation;
|
4
|
+
using RAutomation.UIA.Extensions;
|
5
|
+
|
6
|
+
namespace RAutomation.UIA
|
7
|
+
{
|
8
|
+
public class ExpandibleCollapsibleContainer
|
9
|
+
{
|
10
|
+
protected readonly AutomationElement _element;
|
11
|
+
|
12
|
+
protected ExpandibleCollapsibleContainer(AutomationElement element)
|
13
|
+
{
|
14
|
+
_element = element;
|
15
|
+
}
|
16
|
+
|
17
|
+
protected IEnumerable<ExpandCollapsePattern> ExpandCollapsItems
|
18
|
+
{
|
19
|
+
get { return Elements.Select(x => x.As<ExpandCollapsePattern>(ExpandCollapsePattern.Pattern)); }
|
20
|
+
}
|
21
|
+
|
22
|
+
protected IEnumerable<AutomationElement> Elements
|
23
|
+
{
|
24
|
+
get { return _element.Find(AutomationElement.IsExpandCollapsePatternAvailableProperty.TrueCondition()); }
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
public class Expander : ExpandibleCollapsibleContainer
|
29
|
+
{
|
30
|
+
public Expander(AutomationElement element) : base(element)
|
31
|
+
{}
|
32
|
+
|
33
|
+
public void Expand(int index)
|
34
|
+
{
|
35
|
+
ExpandCollapsItems.ElementAt(index).Expand();
|
36
|
+
}
|
37
|
+
|
38
|
+
public void Expand(string value)
|
39
|
+
{
|
40
|
+
Elements.FirstOrDefault(x => x.Current.Name == value).As<ExpandCollapsePattern>(ExpandCollapsePattern.Pattern).Expand();
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
public class Collapser : ExpandibleCollapsibleContainer
|
45
|
+
{
|
46
|
+
public Collapser(AutomationElement element) : base(element)
|
47
|
+
{}
|
48
|
+
|
49
|
+
public void Collapse(int index)
|
50
|
+
{
|
51
|
+
ExpandCollapsItems.ElementAt(index).Collapse();
|
52
|
+
}
|
53
|
+
|
54
|
+
public void Collapse(string value)
|
55
|
+
{
|
56
|
+
Elements.FirstOrDefault(x => x.Current.Name == value).As<ExpandCollapsePattern>(ExpandCollapsePattern.Pattern).Collapse();
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
@@ -0,0 +1,166 @@
|
|
1
|
+
using System;
|
2
|
+
using System.Threading;
|
3
|
+
using System.Windows;
|
4
|
+
using System.Windows.Automation;
|
5
|
+
|
6
|
+
namespace RAutomation.UIA.Extensions
|
7
|
+
{
|
8
|
+
public static class Element
|
9
|
+
{
|
10
|
+
public static SelectionItemPattern AsSelectionItem(this AutomationElement automationElement)
|
11
|
+
{
|
12
|
+
return (SelectionItemPattern)automationElement.GetCurrentPattern(SelectionItemPattern.Pattern);
|
13
|
+
}
|
14
|
+
|
15
|
+
public static bool Exists(this AutomationElement automationElement)
|
16
|
+
{
|
17
|
+
return null != automationElement;
|
18
|
+
}
|
19
|
+
|
20
|
+
public static string Name(this AutomationElement automationElement)
|
21
|
+
{
|
22
|
+
return automationElement.Current.Name;
|
23
|
+
}
|
24
|
+
|
25
|
+
public static string ClassName(this AutomationElement automationElement)
|
26
|
+
{
|
27
|
+
return automationElement.Current.ClassName;
|
28
|
+
}
|
29
|
+
|
30
|
+
public static bool IsEnabled(this AutomationElement automationElement)
|
31
|
+
{
|
32
|
+
return automationElement.Current.IsEnabled;
|
33
|
+
}
|
34
|
+
|
35
|
+
public static bool IsFocused(this AutomationElement automationElement)
|
36
|
+
{
|
37
|
+
return automationElement.Current.HasKeyboardFocus;
|
38
|
+
}
|
39
|
+
|
40
|
+
public static string HelpText(this AutomationElement automationElement)
|
41
|
+
{
|
42
|
+
return automationElement.Current.HelpText;
|
43
|
+
}
|
44
|
+
|
45
|
+
public static int NativeWindowHandle(this AutomationElement automationElement)
|
46
|
+
{
|
47
|
+
return automationElement.Exists() ? automationElement.Current.NativeWindowHandle : 0;
|
48
|
+
}
|
49
|
+
|
50
|
+
public static Rect BoundingRectangle(this AutomationElement automationElement)
|
51
|
+
{
|
52
|
+
return automationElement.Current.BoundingRectangle;
|
53
|
+
}
|
54
|
+
|
55
|
+
public static ControlType ControlType(this AutomationElement automationElement)
|
56
|
+
{
|
57
|
+
return automationElement.Current.ControlType;
|
58
|
+
}
|
59
|
+
|
60
|
+
public static int ProcessId(this AutomationElement automationElement)
|
61
|
+
{
|
62
|
+
return automationElement.Current.ProcessId;
|
63
|
+
}
|
64
|
+
|
65
|
+
public static bool IsSelected(this AutomationElement automationElement)
|
66
|
+
{
|
67
|
+
return automationElement.AsSelectionItem().Current.IsSelected;
|
68
|
+
}
|
69
|
+
|
70
|
+
public static bool IsOffscreen(this AutomationElement automationElement)
|
71
|
+
{
|
72
|
+
return automationElement.Current.IsOffscreen;
|
73
|
+
}
|
74
|
+
|
75
|
+
public static TogglePattern AsTogglePattern(this AutomationElement automationElement)
|
76
|
+
{
|
77
|
+
return (TogglePattern)automationElement.GetCurrentPattern(TogglePattern.Pattern);
|
78
|
+
}
|
79
|
+
|
80
|
+
public static bool IsToggled(this AutomationElement automationElement)
|
81
|
+
{
|
82
|
+
return automationElement.AsTogglePattern().Current.ToggleState == ToggleState.On;
|
83
|
+
}
|
84
|
+
|
85
|
+
public static string Value(this AutomationElement automationElement)
|
86
|
+
{
|
87
|
+
return automationElement.AsValuePattern().Current.Value;
|
88
|
+
}
|
89
|
+
|
90
|
+
public static void SendKeys(this AutomationElement automationElement, string keysToSend)
|
91
|
+
{
|
92
|
+
automationElement.SetFocus();
|
93
|
+
System.Windows.Forms.SendKeys.SendWait(keysToSend);
|
94
|
+
}
|
95
|
+
|
96
|
+
public static void SetValue(this AutomationElement automationElement, string value)
|
97
|
+
{
|
98
|
+
automationElement.AsValuePattern().SetValue(value);
|
99
|
+
}
|
100
|
+
|
101
|
+
public static bool IsValuePattern(this AutomationElement automationElement)
|
102
|
+
{
|
103
|
+
return (bool)automationElement.GetCurrentPropertyValue(AutomationElement.IsValuePatternAvailableProperty);
|
104
|
+
}
|
105
|
+
|
106
|
+
public static bool CanScrollTo(this AutomationElement automationElement)
|
107
|
+
{
|
108
|
+
return (bool)automationElement.GetCurrentPropertyValue(AutomationElement.IsScrollItemPatternAvailableProperty);
|
109
|
+
}
|
110
|
+
|
111
|
+
public static ScrollItemPattern AsScrollItem(this AutomationElement automationElement)
|
112
|
+
{
|
113
|
+
return automationElement.As<ScrollItemPattern>(ScrollItemPatternIdentifiers.Pattern);
|
114
|
+
}
|
115
|
+
|
116
|
+
public static bool HasClickablePoint(this AutomationElement automationElement)
|
117
|
+
{
|
118
|
+
Point point;
|
119
|
+
return automationElement.TryGetClickablePoint(out point);
|
120
|
+
}
|
121
|
+
|
122
|
+
public static bool ScrollToIfPossible(this AutomationElement automationElement)
|
123
|
+
{
|
124
|
+
if (!automationElement.CanScrollTo())
|
125
|
+
{
|
126
|
+
return false;
|
127
|
+
}
|
128
|
+
|
129
|
+
if (!automationElement.HasClickablePoint())
|
130
|
+
{
|
131
|
+
automationElement.AsScrollItem().ScrollIntoView();
|
132
|
+
automationElement.WaitUntilClickable(3);
|
133
|
+
}
|
134
|
+
|
135
|
+
return true;
|
136
|
+
}
|
137
|
+
|
138
|
+
public static void WaitUntilClickable(this AutomationElement automationElement, int howManySeconds)
|
139
|
+
{
|
140
|
+
var then = DateTime.Now;
|
141
|
+
while (!automationElement.HasClickablePoint())
|
142
|
+
{
|
143
|
+
Thread.Sleep(1);
|
144
|
+
if ((DateTime.Now - then).Seconds > howManySeconds)
|
145
|
+
{
|
146
|
+
throw new Exception(string.Format("Waited for more than {0} seconds to be able to click this", howManySeconds));
|
147
|
+
}
|
148
|
+
}
|
149
|
+
}
|
150
|
+
|
151
|
+
public static ValuePattern AsValuePattern(this AutomationElement automationElement)
|
152
|
+
{
|
153
|
+
return (ValuePattern)automationElement.GetCurrentPattern(ValuePattern.Pattern);
|
154
|
+
}
|
155
|
+
|
156
|
+
public static TextPattern AsTextPattern(this AutomationElement automationElement)
|
157
|
+
{
|
158
|
+
return (TextPattern)automationElement.GetCurrentPattern(TextPattern.Pattern);
|
159
|
+
}
|
160
|
+
|
161
|
+
public static T As<T>(this AutomationElement automationElement, AutomationPattern pattern)
|
162
|
+
{
|
163
|
+
return (T)automationElement.GetCurrentPattern(pattern);
|
164
|
+
}
|
165
|
+
}
|
166
|
+
}
|