Skip to content

Commit e2dbb37

Browse files
ritroJake Ginnivan
authored andcommitted
Comments to many methods, mainly about exceptions.
1 parent f3302ed commit e2dbb37

File tree

10 files changed

+114
-43
lines changed

10 files changed

+114
-43
lines changed

src/TestStack.White/Application.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ private Application(Process process)
4040
/// </summary>
4141
/// <param name="executable">location of the executable</param>
4242
/// <returns></returns>
43+
/// <exception cref="ArgumentNullException"></exception>
44+
/// <exception cref="WhiteException">when some error occured</exception>
4345
public static Application Launch(string executable)
4446
{
4547
var processStartInfo = new ProcessStartInfo(executable);
@@ -51,6 +53,8 @@ public static Application Launch(string executable)
5153
/// </summary>
5254
/// <param name="processStartInfo"></param>
5355
/// <returns></returns>
56+
/// <exception cref="ArgumentNullException"></exception>
57+
/// <exception cref="WhiteException">when some error occured</exception>
5458
public static Application Launch(ProcessStartInfo processStartInfo)
5559
{
5660
if (string.IsNullOrEmpty(processStartInfo.WorkingDirectory)) processStartInfo.WorkingDirectory = ".";
@@ -93,10 +97,18 @@ public static Application Launch(ProcessStartInfo processStartInfo)
9397
/// </summary>
9498
/// <param name="processId"></param>
9599
/// <returns></returns>
100+
/// <exception cref="WhiteException">when process not found</exception>
96101
public static Application Attach(int processId)
97102
{
98-
Process process = Process.GetProcessById(processId);
99-
if (process == null) throw new WhiteException("Could not find process with id: " + processId);
103+
Process process = null;
104+
try
105+
{
106+
process = Process.GetProcessById(processId);
107+
}
108+
catch (System.ArgumentException e)
109+
{
110+
throw new WhiteException("Could not find process with id: " + processId, e);
111+
}
100112
return new Application(process);
101113
}
102114

@@ -115,6 +127,7 @@ public static Application Attach(Process process)
115127
/// </summary>
116128
/// <param name="executable"></param>
117129
/// <returns></returns>
130+
/// <exception cref="WhiteException">when process is not found</exception>
118131
public static Application Attach(string executable)
119132
{
120133
Process[] processes = Process.GetProcessesByName(executable);
@@ -127,6 +140,9 @@ public static Application Attach(string executable)
127140
/// </summary>
128141
/// <param name="processStartInfo"></param>
129142
/// <returns></returns>
143+
/// <exception cref="ArgumentException"></exception>
144+
/// <exception cref="ArgumentNullException"></exception>
145+
/// <exception cref="WhiteException">when some error occured</exception>
130146
public static Application AttachOrLaunch(ProcessStartInfo processStartInfo)
131147
{
132148
string processName = ReplaceLast(processStartInfo.FileName, ".exe", string.Empty);
@@ -165,17 +181,19 @@ public virtual ApplicationSession ApplicationSession
165181
/// <param name="title">Title text of window displayed on desktop</param>
166182
/// <param name="option">Option which would be used to initialize the window.</param>
167183
/// <returns></returns>
184+
/// <exception cref="UIItemSearchException">if your framework is not supported</exception>
168185
public virtual Window GetWindow(string title, InitializeOption option)
169186
{
170187
WindowSession windowSession = applicationSession.WindowSession(option);
171188
return windowFactory.CreateWindow(title, process, option, windowSession);
172189
}
173190

174191
/// <summary>
175-
/// Get visible window
192+
/// Get visible window. NoCache option is set by default
176193
/// </summary>
177194
/// <param name="title">Title text of window displayed on desktop</param>
178195
/// <returns></returns>
196+
/// <exception cref="UIItemSearchException">if your framework is not supported</exception>
179197
public virtual Window GetWindow(string title)
180198
{
181199
return GetWindow(title, InitializeOption.NoCache);
@@ -187,6 +205,7 @@ public virtual Window GetWindow(string title)
187205
/// <param name="searchCriteria"></param>
188206
/// <param name="initializeOption">found window would be initialized with this option</param>
189207
/// <returns></returns>
208+
/// <exception cref="UIItemSearchException">if your framework is not supported</exception>
190209
public virtual Window GetWindow(SearchCriteria searchCriteria, InitializeOption initializeOption)
191210
{
192211
WindowSession windowSession = applicationSession.WindowSession(initializeOption);
@@ -234,6 +253,7 @@ public virtual void Kill()
234253
/// All windows belonging to the application
235254
/// </summary>
236255
/// <returns></returns>
256+
/// <exception cref="UIItemSearchException">if your framework is not supported</exception>
237257
public virtual List<Window> GetWindows()
238258
{
239259
return windowFactory.DesktopWindows(process, new NoApplicationSession());
@@ -289,6 +309,7 @@ public virtual void WaitWhileBusy()
289309
/// </summary>
290310
/// <param name="match"></param>
291311
/// <param name="initializeOption">option for the window which matches the condition</param>
312+
/// <exception cref="UIItemSearchException">if your framework is not supported</exception>
292313
public virtual Window Find(Predicate<string> match, InitializeOption initializeOption)
293314
{
294315
WindowSession windowSession = applicationSession.WindowSession(initializeOption);

src/TestStack.White/Factory/ChildWindowFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ protected virtual AutomationElement WaitTillFound(Func<AutomationElement> find,
4444
return element;
4545
}
4646

47+
/// <exception cref="UIItemSearchException">if your framework is not supported</exception>
4748
internal static Window Create(AutomationElement element, InitializeOption option, WindowSession windowSession)
4849
{
4950
SpecializedWindowFactory specializedWindowFactory = SpecializedWindowFactories.Find(factory => factory.DoesSpecializeInThis(element));

src/TestStack.White/Factory/WindowFactory.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,31 @@ public virtual Window SplashWindow(Process process)
6868
return new SplashWindow(element, InitializeOption.NoCache);
6969
}
7070

71+
/// <exception cref="UIItemSearchException">if your framework is not supported</exception>
7172
public virtual Window CreateWindow(string title, Process process, InitializeOption option, WindowSession windowSession)
7273
{
7374
var message = string.Format("Couldn't find window with title {0} in process {1}{2}", title, process.Id, ", after waiting for 30 seconds");
7475
var element = WaitTillFound(() => Finder.FindWindow(title, process.Id), message);
7576
return Create(element, option, windowSession);
7677
}
7778

79+
/// <exception cref="UIItemSearchException">if your framework is not supported</exception>
7880
public virtual Window CreateWindow(SearchCriteria searchCriteria, Process process, InitializeOption option, WindowSession windowSession)
7981
{
8082
var message = string.Format("Couldn't find window with SearchCriteria {0} in process {1}{2}", searchCriteria, process.Id, Constants.BusyMessage);
8183
var element = WaitTillFound(() => Finder.FindWindow(searchCriteria, process.Id), message);
8284
return Create(element, option, windowSession);
8385
}
8486

87+
/// <exception cref="UIItemSearchException">if your framework is not supported</exception>
8588
public virtual Window FindWindow(Process process, Predicate<string> match, InitializeOption initializeOption, WindowSession windowSession)
8689
{
8790
string message = string.Format("Could not find window matching condition. ProcessName: {0}, ProcessId: {1}, MatchingConditionMethod: {2}, MatchingConditionTarget: {3}", process.ProcessName, process.Id, match.Method, match.Target);
8891
var foundElement = WaitTillFound(() => FindWindowElement(process, match), message);
8992
return Create(foundElement, initializeOption, windowSession);
9093
}
9194

95+
/// <exception cref="UIItemSearchException">if your framework is not supported</exception>
9296
public virtual Window FindModalWindow(string title, Process process, InitializeOption option, AutomationElement parentWindowElement,
9397
WindowSession windowSession)
9498
{
@@ -98,6 +102,7 @@ public virtual Window FindModalWindow(string title, Process process, InitializeO
98102
return Create(modalWindowElement, option, windowSession);
99103
}
100104

105+
/// <exception cref="UIItemSearchException">if your framework is not supported</exception>
101106
public virtual Window FindModalWindow(SearchCriteria searchCriteria, InitializeOption option, AutomationElement parentWindowElement, WindowSession windowSession)
102107
{
103108
var windowFinder = new AutomationElementFinder(parentWindowElement);
@@ -132,6 +137,7 @@ private AutomationElement FindWindowElement(Process process, Predicate<string> m
132137
});
133138
}
134139

140+
/// <exception cref="UIItemSearchException">if your framework is not supported</exception>
135141
public virtual List<Window> DesktopWindows()
136142
{
137143
var windows = new List<Window>();

src/TestStack.White/UIItems/IUIItem.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,13 @@ public interface IUIItem : ActionListener
9595

9696
void Enter(string value);
9797
}
98+
99+
/// <summary>
100+
/// Class which inherits this interface has a mapping to it's Automation type.
101+
/// Used for search constraints.
102+
/// </summary>
103+
public interface IMappableUIItem
104+
{
105+
106+
}
98107
}

src/TestStack.White/UIItems/IUIItemContainer.cs

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,58 @@ namespace TestStack.White.UIItems
44
{
55
public interface IUIItemContainer : IUIItem
66
{
7-
T Get<T>() where T : UIItem;
8-
T Get<T>(string primaryIdentification) where T : UIItem;
9-
T Get<T>(SearchCriteria searchCriteria) where T : UIItem;
107
ToolTip ToolTip { get; }
118
ToolTip GetToolTipOn(UIItem uiItem);
129
IUIItem[] GetMultiple(SearchCriteria criteria);
10+
11+
/// <summary>
12+
/// Finds UIItem which matches specified type. Useful for non managed applications where controls are not identified by AutomationId, like in
13+
/// Managed applications. In case of multiple items of this type the first one found would be returned which cannot be guaranteed to be the same
14+
/// across multiple invocations.
15+
/// </summary>
16+
/// <typeparam name="T">IUIItem type e.g. Button, TextBox</typeparam>
17+
/// <returns>First item of supplied type</returns>
18+
/// <exception cref="AutomationException">when item not found</exception>
19+
/// <exception cref="WhiteException">when any errors occured during search</exception>
20+
T Get<T>() where T : IUIItem;
21+
22+
/// <summary>
23+
/// Finds UIItem which matches specified type and identification.
24+
/// In case of multiple items of this type the first one found would be returned which cannot be guaranteed to be the same across multiple
25+
/// invocations. For managed applications this is name given to controls in the application code.
26+
/// For unmanaged applications this is text of the control or label next to it if it doesn't have well defined text.
27+
/// <!--e.g. TextBox doesn't have any predefined text of its own as it can be changed at runtime by user, hence is identified by the label next to it.
28+
/// If there is no label then Get<T> or Get<T>(SearchCriteria) method can be used.-->
29+
/// </summary>
30+
/// <typeparam name="T">IUIItem implementation</typeparam>
31+
/// <param name="primaryIdentification">For managed application this is the name provided in application code and unmanaged application this is
32+
/// the text or label next to it based identification</param>
33+
/// <returns>First item of supplied type and identification</returns>
34+
/// <exception cref="AutomationException">when item not found</exception>
35+
/// <exception cref="WhiteException">when any errors occured during search</exception>
36+
T Get<T>(string primaryIdentification) where T : IUIItem;
37+
38+
/// <summary>
39+
/// Finds UIItem which matches specified type and searchCriteria. Type supplied need not be supplied again in SearchCondition.
40+
/// <!--e.g. in Get<Button>(SearchCriteria.ByAutomationId("OK").ByControlType(typeof(Button)).Indexed(1) the ByControlType(typeof(Button)) part
41+
/// is redundant. Look at documentation of SearchCriteria for details on it.-->
42+
/// </summary>
43+
/// <code>
44+
/// </code>
45+
/// <typeparam name="T"></typeparam>
46+
/// <param name="searchCriteria">Criteria provided to search UIItem</param>
47+
/// <returns>First items matching the type and criteria</returns>
48+
/// <exception cref="AutomationException">when item not found</exception>
49+
/// <exception cref="WhiteException">when any errors occured during search</exception>
50+
T Get<T>(SearchCriteria searchCriteria) where T : IUIItem;
51+
52+
/// <summary>
53+
/// Finds UIItem which matches specified type and searchCriteria using the default BusyTimeout. Look at documentation of SearchCriteria for details on it.
54+
/// </summary>
55+
/// <param name="searchCriteria">Criteria provided to search IUIItem</param>
56+
/// <returns>First items matching the criteria</returns>
57+
/// <exception cref="AutomationException">when item not found</exception>
58+
/// <exception cref="WhiteException">when any errors occured during search</exception>
59+
IUIItem Get(SearchCriteria searchCriteria);
1360
}
1461
}

src/TestStack.White/UIItems/ListViewCells.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public ListViewCells(List<AutomationElement> collection, ActionListener actionLi
1616
this.header = header;
1717
}
1818

19+
/// <exception cref="UIActionException">when header row is not defined</exception>
1920
public virtual ListViewCell this[string columnName]
2021
{
2122
get

src/TestStack.White/UIItems/SelectionItem.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public virtual bool IsSelected
1919
}
2020
}
2121

22+
/// <exception cref="UIActionException"></exception>
2223
public virtual void Select()
2324
{
2425
if (!Bounds.IsEmpty) Click();

src/TestStack.White/UIItems/TextBox.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public TextBox(AutomationElement automationElement, ActionListener actionListene
1414

1515
/// <summary>
1616
/// Enters the text in the textbox. The text would be cleared first. This is not as good performing as the BulkText method.
17-
/// This does raise all keyboard events.
17+
/// This does raise all keyboard events - that means that your string will consist of letters that match the letters
18+
/// of your string but in current input language.
1819
/// </summary>
1920
public virtual string Text
2021
{
@@ -34,6 +35,7 @@ public virtual string Text
3435

3536
/// <summary>
3637
/// Sets the text in the textbox. The text would be cleared first. This is a better performing than the Text method. This doesn't raise all keyboard events.
38+
/// The string will be set exactly as it is in your code.
3739
/// </summary>
3840
public virtual string BulkText
3941
{

src/TestStack.White/UIItems/UIItemContainer.cs

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -45,53 +45,21 @@ public UIItemContainer(AutomationElement automationElement, ActionListener actio
4545
{
4646
}
4747

48-
/// <summary>
49-
/// Finds UIItem which matches specified type. Useful for non managed applications where controls are not identified by AutomationId, like in
50-
/// Managed applications. In case of multiple items of this type the first one found would be returned which cannot be guaranteed to be the same
51-
/// across multiple invocations.
52-
/// </summary>
53-
/// <typeparam name="T">UIItem type e.g. Button, TextBox</typeparam>
54-
/// <returns>First item of supplied type</returns>
55-
public virtual T Get<T>() where T : UIItem
48+
public virtual T Get<T>() where T : IUIItem
5649
{
5750
return Get<T>(SearchCriteria.All);
5851
}
5952

60-
/// <summary>
61-
/// Finds UIItem which matches specified type and identification.
62-
/// In case of multiple items of this type the first one found would be returned which cannot be guaranteed to be the same across multiple
63-
/// invocations. For managed applications this is name given to controls in the application code.
64-
/// For unmanaged applications this is text of the control or label next to it if it doesn't have well defined text.
65-
/// e.g. TextBox doesn't have any predefined text of its own as it can be changed at runtime by user, hence is identified by the label next to it.
66-
/// If there is no label then Get<T> or Get<T>(SearchCriteria) method can be used.
67-
/// </summary>
68-
/// <typeparam name="T">UIItem type</typeparam>
69-
/// <param name="primaryIdentification">For managed application this is the name provided in application code and unmanaged application this is
70-
/// the text or label next to it based identification</param>
71-
/// <returns>First item of supplied type and identification</returns>
72-
public virtual T Get<T>(string primaryIdentification) where T : UIItem
53+
public virtual T Get<T>(string primaryIdentification) where T : IUIItem
7354
{
7455
return Get<T>(SearchCriteria.ByAutomationId(primaryIdentification));
7556
}
7657

77-
/// <summary>
78-
/// Finds UIItem which matches specified type and searchCriteria. Type supplied need not be supplied again in SearchCondition.
79-
/// e.g. in Get<Button>(SearchCriteria.ByAutomationId("OK").ByControlType(typeof(Button)).Indexed(1) the ByControlType(typeof(Button)) part
80-
/// is redundant. Look at documentation of SearchCriteria for details on it.
81-
/// </summary>
82-
/// <typeparam name="T"></typeparam>
83-
/// <param name="searchCriteria">Criteria provided to search UIItem</param>
84-
/// <returns>First items matching the type and criteria</returns>
85-
public virtual T Get<T>(SearchCriteria searchCriteria) where T : UIItem
58+
public virtual T Get<T>(SearchCriteria searchCriteria) where T : IUIItem
8659
{
8760
return (T) Get(searchCriteria.AndControlType(typeof (T), Framework));
8861
}
8962

90-
/// <summary>
91-
/// Finds UIItem which matches specified type and searchCriteria using the default BusyTimeout. Look at documentation of SearchCriteria for details on it.
92-
/// </summary>
93-
/// <param name="searchCriteria">Criteria provided to search UIItem</param>
94-
/// <returns>First items matching the criteria</returns>
9563
public virtual IUIItem Get(SearchCriteria searchCriteria)
9664
{
9765
return Get(searchCriteria, CoreAppXmlConfiguration.Instance.BusyTimeout());
@@ -100,9 +68,11 @@ public virtual IUIItem Get(SearchCriteria searchCriteria)
10068
/// <summary>
10169
/// Finds UIItem which matches specified type and searchCriteria. Look at documentation of SearchCriteria for details on it.
10270
/// </summary>
103-
/// <param name="searchCriteria">Criteria provided to search UIItem</param>
71+
/// <param name="searchCriteria">Criteria provided to search IUIItem</param>
10472
/// <param name="timeout">Time to wait for item to come on-screen before returning off-screen element, if found.</param>
10573
/// <returns>First items matching the criteria</returns>
74+
/// <exception cref="AutomationException">when item not found</exception>
75+
/// <exception cref="WhiteException">when any errors occured during search</exception>
10676
public virtual IUIItem Get(SearchCriteria searchCriteria, TimeSpan timeout)
10777
{
10878
try

0 commit comments

Comments
 (0)