Skip to content

Commit 9636dd6

Browse files
committed
Cleaning Up UIItem
Cleaning Up UIItem and IUIItem - Adding Regions for sets of Functionality such as 'Interaction with an UI Item', 'Properties of an UI Item', etc - Renamed the RaiseClickEvent to Invoke - Added code documentation - Moved some public properties and functions also into the Interface to get the Interface and implementing class in Synch - Renamed UIItemEventListener to IUIItemEventListener
1 parent cfe7fa7 commit 9636dd6

File tree

17 files changed

+604
-265
lines changed

17 files changed

+604
-265
lines changed

src/TestStack.White.UITests/ControlTests/ButtonTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ public void ThrowsWhenNotFound()
3535
}
3636

3737
[Test]
38-
public void RaiseClickEvent()
38+
public void TestInvokePattern()
3939
{
4040
var button = MainWindow.Get<Button>("ButtonWithTooltip");
41-
button.RaiseClickEvent();
41+
button.Invoke();
4242
Assert.That(button.Text, Is.EqualTo("Clicked"));
4343
}
4444
}

src/TestStack.White/Recording/SafeAutomationEventHandler.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ public class SafeAutomationEventHandler
1111
{
1212
private readonly IUIItem uiItem;
1313
private readonly Create createUserEvent;
14-
private readonly UIItemEventListener eventListener;
14+
private readonly IUIItemEventListener eventListener;
1515
private readonly ILogger logger = CoreAppXmlConfiguration.Instance.LoggerFactory.Create(typeof(SafeAutomationEventHandler));
1616

1717
public delegate UserEvent Create(object[] parameters);
1818

19-
public SafeAutomationEventHandler(IUIItem uiItem, UIItemEventListener eventListener, Create createUserEvent)
19+
public SafeAutomationEventHandler(IUIItem uiItem, IUIItemEventListener eventListener, Create createUserEvent)
2020
{
2121
this.uiItem = uiItem;
2222
this.eventListener = eventListener;

src/TestStack.White/Recording/UIItemEventListener.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace TestStack.White.Recording
44
{
5-
public interface UIItemEventListener
5+
public interface IUIItemEventListener
66
{
77
void EventOccured(UserEvent userEvent);
88
}

src/TestStack.White/UIItems/Button.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public Button(AutomationElement automationElement, IActionListener actionListene
1515
toggleableItem = new ToggleableItem(this);
1616
}
1717

18-
public override void HookEvents(UIItemEventListener eventListener)
18+
public override void HookEvents(IUIItemEventListener eventListener)
1919
{
2020
HookClickEvent(eventListener);
2121
}

src/TestStack.White/UIItems/CheckBox.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public virtual void UnSelect()
4848
Checked = false;
4949
}
5050

51-
public override void HookEvents(UIItemEventListener eventListener)
51+
public override void HookEvents(IUIItemEventListener eventListener)
5252
{
5353
handler = delegate
5454
{

src/TestStack.White/UIItems/Hyperlink.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public virtual void Click(int xOffset, int yOffset)
1717
mouse.Click(new Point((int) x, (int) y), actionListener);
1818
}
1919

20-
public override void HookEvents(UIItemEventListener eventListener)
20+
public override void HookEvents(IUIItemEventListener eventListener)
2121
{
2222
HookClickEvent(eventListener);
2323
}

src/TestStack.White/UIItems/IUIItem.cs

+226-44
Original file line numberDiff line numberDiff line change
@@ -13,69 +13,220 @@ namespace TestStack.White.UIItems
1313
{
1414
public interface IUIItem : IActionListener
1515
{
16+
#region Automation
17+
1618
/// <summary>
1719
/// Should be used only if white doesn't support the feature you are looking for.
1820
/// Knowledge of UIAutomation would be required. It would better idea to also raise an issue if you are using it.
1921
/// </summary>
2022
AutomationElement AutomationElement { get; }
2123

22-
bool Enabled { get; }
24+
/// <summary>
25+
/// The <see cref="WindowsFramework"/> of the UI Item
26+
/// </summary>
2327
WindowsFramework Framework { get; }
24-
Point Location { get; }
25-
Rect Bounds { get; }
28+
29+
/// <summary>
30+
/// The <see cref="IActionListener"/> of the UI Item
31+
/// </summary>
32+
IActionListener ActionListener { get; }
33+
34+
/// <summary>
35+
/// Uses the Raw View provided by UIAutomation to find elements within this UIItem.
36+
/// RawView sometimes contains extra AutomationElements.
37+
/// This is internal to white although made public.
38+
/// Should be used only if the standard approaches dont work.
39+
/// Also if you end up using it please raise an issue so that it can be fixed.
40+
/// Please understand that calling this method on any UIItem,
41+
/// which has a lot of child AutomationElements might result in very bad performance.
42+
/// </summary>
43+
/// <param name="searchCriteria"></param>
44+
/// <returns>null or found AutomationElement</returns>
45+
AutomationElement GetElement(SearchCriteria searchCriteria);
46+
47+
#endregion
48+
49+
#region State Properties
50+
51+
/// <summary>
52+
/// Is UI Item Enabled
53+
/// </summary>
54+
bool Enabled { get; }
55+
56+
/// <summary>
57+
/// Is UI Item Off Screen
58+
/// </summary>
59+
bool IsOffScreen { get; }
60+
61+
/// <summary>
62+
/// Is UI Item Visible
63+
/// </summary>
64+
bool Visible { get; }
65+
66+
/// <summary>
67+
/// Is UI Item Focussed
68+
/// </summary>
69+
bool IsFocussed { get; }
70+
71+
/// <summary>
72+
/// The Status of the UI Item
73+
/// </summary>
74+
string ItemStatus { get; }
75+
76+
/// <summary>
77+
/// Name of the UI Item
78+
/// </summary>
2679
string Name { get; }
27-
Point ClickablePoint { get; }
28-
string AccessKey { get; }
80+
81+
/// <summary>
82+
/// ID of the UI Item
83+
/// </summary>
2984
string Id { get; }
30-
bool Visible { get; }
85+
86+
/// <summary>
87+
/// Primary Identification of the UI Item
88+
/// </summary>
3189
string PrimaryIdentification { get; }
32-
IActionListener ActionListener { get; }
90+
91+
/// <summary>
92+
/// Access Key of the UI Item
93+
/// </summary>
94+
string AccessKey { get; }
95+
96+
/// <summary>
97+
/// HelpText of the UI Item
98+
/// </summary>
99+
string HelpText { get; }
100+
101+
/// <summary>
102+
/// <see cref="IScrollBars"/> of the UI Item
103+
/// </summary>
33104
IScrollBars ScrollBars { get; }
34-
bool IsOffScreen { get; }
35-
bool IsFocussed { get; }
105+
106+
#endregion
107+
108+
#region Dimension Properties
109+
110+
/// <summary>
111+
/// <see cref="Point"/> location of the UI Item
112+
/// </summary>
113+
Point Location { get; }
114+
115+
/// <summary>
116+
/// <see cref="Rect"/> Bounds of the UI Item
117+
/// </summary>
118+
Rect Bounds { get; }
119+
120+
/// <summary>
121+
/// <see cref="Point"/> ClickablePoint of the UI Item
122+
/// </summary>
123+
Point ClickablePoint { get; }
124+
125+
#endregion
126+
127+
#region Graphics
128+
129+
/// <summary>
130+
/// <see cref="Color"/> of the UI Item Border
131+
/// </summary>
36132
Color BorderColor { get; }
133+
134+
/// <summary>
135+
/// <see cref="Bitmap"/> representing the VisibleImage of the UI Item
136+
/// </summary>
37137
Bitmap VisibleImage { get; }
38-
bool ValueOfEquals(AutomationProperty property, object compareTo);
39-
void RightClickAt(Point point);
40-
void RightClick();
138+
139+
/// <summary>
140+
/// Draw a Highlighting around the UI Item in the Color <see cref="Color.Red"/>
141+
/// </summary>
142+
void DrawHighlight();
143+
144+
/// <summary>
145+
/// Draw a Highlighting around the UI Item in a specific color
146+
/// </summary>
147+
/// <param name="color">Color of the Highlighting</param>
148+
void DrawHighlight(Color color);
149+
150+
/// <summary>
151+
/// Capture a <see cref="Bitmap"/> image of the UI Item
152+
/// </summary>
153+
Bitmap Capture();
154+
155+
#endregion
156+
157+
#region Interaction
158+
159+
/// <summary>
160+
/// Focus the UI Item
161+
/// </summary>
41162
void Focus();
42163

43164
/// <summary>
44-
/// An alternative to use instead of Focus, might sometimes be more reliable
165+
/// Bring the UI Item to the Foreground
45166
/// </summary>
167+
/// <remarks>
168+
/// An alternative to use instead of Focus, might sometimes be more reliable
169+
/// </remarks>
46170
void SetForeground();
47-
171+
172+
/// <summary>
173+
/// Visit the UI Item
174+
/// </summary>
175+
/// <param name="windowControlVisitor">Window Control Visitor</param>
48176
void Visit(IWindowControlVisitor windowControlVisitor);
49177

50178
/// <summary>
51-
/// Provides the Error on this UIItem.
52-
/// This would return Error object when this item has ErrorProvider displayed next to it.
179+
/// Performs an Invoke on the <see cref="InvokePattern"/> Pattern of the UI Item
53180
/// </summary>
54-
/// <param name="window"></param>
55-
/// <returns></returns>
56-
string ErrorProviderMessage(Window window);
57-
58-
bool NameMatches(string text);
181+
/// <remarks>
182+
/// This is faster then a <see cref="Click()"/> on the UI Item.
183+
/// Can have some side effects that certain Click Events are bypassed.
184+
/// </remarks>
185+
void Invoke();
59186

60187
/// <summary>
61-
/// Performs mouse click at the center of this item
188+
/// Performs mouse click at the center of the UI Item
62189
/// </summary>
63190
void Click();
64191

65192
/// <summary>
66-
/// Performs mouse double click at the center of this item
193+
/// Performs mouse double click at the center of the UI Item
67194
/// </summary>
68195
void DoubleClick();
69196

70197
/// <summary>
71-
///Perform keyboard action on this UIItem
198+
/// Performs a right mouse click at the center of the UI Item
199+
/// </summary>
200+
void RightClick();
201+
202+
/// <summary>
203+
/// Performas a right mouse click at a defined <remarks>Point</remarks>
204+
/// </summary>
205+
/// <param name="point">Point to mouse right click</param>
206+
void RightClickAt(Point point);
207+
208+
/// <summary>
209+
///Perform keyboard action on this UI Item
72210
/// </summary>
73211
/// <param name="key"></param>
74212
void KeyIn(KeyboardInput.SpecialKeys key);
75213

76-
bool Equals(object obj);
77-
int GetHashCode();
78-
string ToString();
214+
/// <summary>
215+
/// Sets a value on this UI Item
216+
/// </summary>
217+
/// <param name="value">Value to set</param>
218+
void SetValue(object value);
219+
220+
/// <summary>
221+
/// Enter a value on this UI Item
222+
/// </summary>
223+
/// <param name="value">Value to enter</param>
224+
/// <remarks>The <see cref="ValuePattern"/> must be supported by the UI Item for this to work</remarks>
225+
void Enter(string value);
226+
227+
#endregion
228+
229+
#region Recording
79230

80231
/// <summary>
81232
/// Internal to white and intended to be used for white recording
@@ -86,32 +237,63 @@ public interface IUIItem : IActionListener
86237
/// Internal to white and intended to be used for white recording
87238
/// </summary>
88239
/// <param name="eventListener"></param>
89-
void HookEvents(UIItemEventListener eventListener);
240+
void HookEvents(IUIItemEventListener eventListener);
90241

91-
void SetValue(object value);
242+
#endregion
243+
244+
#region Debugging
245+
246+
/// <summary>
247+
/// Provides the Error on this UIItem.
248+
/// This would return Error object when this item has ErrorProvider displayed next to it.
249+
/// </summary>
250+
/// <param name="window"></param>
251+
/// <returns></returns>
252+
string ErrorProviderMessage(Window window);
253+
254+
/// <summary>
255+
/// Log Structure of the UI Item
256+
/// </summary>
92257
void LogStructure();
93258

259+
#endregion
260+
261+
#region Equality
262+
94263
/// <summary>
95-
/// Uses the Raw View provided by UIAutomation to find elements within this UIItem.
96-
/// RawView sometimes contains extra AutomationElements.
97-
/// This is internal to white although made public.
98-
/// Should be used only if the standard approaches dont work.
99-
/// Also if you end up using it please raise an issue so that it can be fixed.
100-
/// Please understand that calling this method on any UIItem,
101-
/// which has a lot of child AutomationElements might result in very bad performance.
264+
/// Check if the UI Item name matches a given name
102265
/// </summary>
103-
/// <param name="searchCriteria"></param>
104-
/// <returns>null or found AutomationElement</returns>
105-
AutomationElement GetElement(SearchCriteria searchCriteria);
266+
/// <param name="text">Name Value to match against</param>
267+
/// <returns>Returns <c>true</c> if matches, else <c>false</c></returns>
268+
bool NameMatches(string text);
106269

107-
void Enter(string value);
270+
/// <summary>
271+
/// Compare the <see cref="AutomationProperty"/> from the UI Item against an object
272+
/// </summary>
273+
/// <param name="property">The <see cref="AutomationProperty"/> value to compare to</param>
274+
/// <param name="compareTo">The object to compare it to</param>
275+
/// <returns>Returns <c>true</c> if matches, else <c>false</c></returns>
276+
bool ValueOfEquals(AutomationProperty property, object compareTo);
108277

109-
void DrawHighlight();
110-
void DrawHighlight(Color color);
278+
/// <summary>
279+
/// CHeck if the UI Item equals an object
280+
/// </summary>
281+
/// <param name="obj">Object to compare to</param>
282+
/// <returns>Returns <c>true</c> if matches, else <c>false</c></returns>
283+
bool Equals(object obj);
111284

112285
/// <summary>
113-
/// Captures an image of the element
286+
/// Get the HashCode of the UI Item
114287
/// </summary>
115-
Bitmap Capture();
288+
/// <returns>The HashCode of the UI Item</returns>
289+
int GetHashCode();
290+
291+
/// <summary>
292+
/// ToString overload for the UI Item
293+
/// </summary>
294+
/// <returns>The String representation of the UI Item</returns>
295+
string ToString();
296+
297+
#endregion
116298
}
117299
}

0 commit comments

Comments
 (0)