Skip to content

Commit 3c342b0

Browse files
committed
Merge branch 'detach-to-prevent-closing' of https://github.com/Roemer/White into Roemer-detach-to-prevent-closing
2 parents 6d8a476 + 0076a73 commit 3c342b0

File tree

4 files changed

+65
-45
lines changed

4 files changed

+65
-45
lines changed

src/TestStack.White/Application.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ public static Application Launch(ProcessStartInfo processStartInfo)
5858
if (string.IsNullOrEmpty(processStartInfo.WorkingDirectory)) processStartInfo.WorkingDirectory = ".";
5959

6060
Logger.DebugFormat("[Launching process:{0}] [Working directory:{1}] [Process full path:{2}] [Current Directory:{3}]",
61-
processStartInfo.FileName,
61+
processStartInfo.FileName,
6262
new DirectoryInfo(processStartInfo.WorkingDirectory).FullName,
63-
new FileInfo(processStartInfo.FileName).FullName,
63+
new FileInfo(processStartInfo.FileName).FullName,
6464
Environment.CurrentDirectory);
6565
Process process;
6666
try
@@ -283,7 +283,10 @@ public override int GetHashCode()
283283

284284
public virtual void Dispose()
285285
{
286-
Kill();
286+
if (!CoreAppXmlConfiguration.Instance.KeepOpenOnDispose)
287+
{
288+
Kill();
289+
}
287290
}
288291

289292
public virtual Window FindSplash()

src/TestStack.White/Configuration/CoreAppXmlConfiguration.cs

+44-36
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ namespace TestStack.White.Configuration
1111
{
1212
public class CoreAppXmlConfiguration : AssemblyConfiguration, ICoreConfiguration
1313
{
14-
private static ICoreConfiguration instance;
14+
private static ICoreConfiguration instance = new CoreAppXmlConfiguration();
1515
private readonly DynamicProxyInterceptors interceptors = new DynamicProxyInterceptors();
16-
1716
private static readonly Dictionary<string, object> DefaultValues = new Dictionary<string, object>();
1817

1918
static CoreAppXmlConfiguration()
@@ -35,12 +34,12 @@ static CoreAppXmlConfiguration()
3534
DefaultValues.Add("MaxElementSearchDepth", 10);
3635
DefaultValues.Add("DoubleClickInterval", 0);
3736
DefaultValues.Add("MoveMouseToGetStatusOfHourGlass", true);
38-
DefaultValues.Add("InvertMouseButtons", true);
37+
DefaultValues.Add("KeepOpenOnDispose", false);
3938
}
4039

4140
public static ICoreConfiguration Instance
4241
{
43-
get { return instance ?? (instance = new CoreAppXmlConfiguration()); }
42+
get { return instance; }
4443
}
4544

4645
private CoreAppXmlConfiguration()
@@ -51,15 +50,32 @@ private CoreAppXmlConfiguration()
5150
LoggerFactory = new WhiteDefaultLoggerFactory(LoggerLevel.Info);
5251
}
5352

53+
public virtual ILoggerFactory LoggerFactory { get; set; }
54+
55+
public virtual IDisposable ApplyTemporarySetting(Action<ICoreConfiguration> changes)
56+
{
57+
var existing = new Dictionary<string, string>(UsedValues);
58+
changes(this);
59+
60+
return new DelegateDisposable(() =>
61+
{
62+
foreach (var value in existing)
63+
{
64+
SetUsedValue(value.Key, value.Value);
65+
}
66+
});
67+
}
68+
5469
private void SetUsedValue(string key, object value)
5570
{
5671
UsedValues[key] = value.ToString();
5772
}
5873

59-
public virtual DirectoryInfo WorkSessionLocation
74+
public virtual IWaitHook AdditionalWaitHook { get; set; }
75+
76+
public virtual DynamicProxyInterceptors Interceptors
6077
{
61-
get { return new DirectoryInfo(UsedValues["WorkSessionLocation"]); }
62-
set { SetUsedValue("WorkSessionLocation", value); }
78+
get { return interceptors; }
6379
}
6480

6581
public virtual int BusyTimeout
@@ -80,9 +96,10 @@ public virtual bool WaitBasedOnHourGlass
8096
set { SetUsedValue("WaitBasedOnHourGlass", value); }
8197
}
8298

83-
public virtual DynamicProxyInterceptors Interceptors
99+
public virtual DirectoryInfo WorkSessionLocation
84100
{
85-
get { return interceptors; }
101+
get { return new DirectoryInfo(UsedValues["WorkSessionLocation"]); }
102+
set { SetUsedValue("WorkSessionLocation", value); }
86103
}
87104

88105
public virtual int UIAutomationZeroWindowBugTimeout
@@ -139,46 +156,37 @@ public virtual bool ComboBoxItemsPopulatedWithoutDropDownOpen
139156
set { SetUsedValue("ComboBoxItemsPopulatedWithoutDropDownOpen", value); }
140157
}
141158

142-
public virtual bool MoveMouseToGetStatusOfHourGlass
143-
{
144-
get { return Convert.ToBoolean(UsedValues["MoveMouseToGetStatusOfHourGlass"]); }
145-
set { SetUsedValue("MoveMouseToGetStatusOfHourGlass", value); }
146-
}
147-
148-
public virtual ILoggerFactory LoggerFactory { get; set; }
149-
150-
public virtual IDisposable ApplyTemporarySetting(Action<ICoreConfiguration> changes)
159+
public virtual bool RawElementBasedSearch
151160
{
152-
var existing = new Dictionary<string, string>(UsedValues);
153-
changes(this);
154-
155-
return new DelegateDisposable(() =>
156-
{
157-
foreach (var value in existing)
158-
{
159-
SetUsedValue(value.Key, value.Value);
160-
}
161-
});
161+
get { return Convert.ToBoolean(UsedValues["RawElementBasedSearch"]); }
162+
set { SetUsedValue("RawElementBasedSearch", value); }
162163
}
163164

164-
public virtual IWaitHook AdditionalWaitHook { get; set; }
165-
166165
public virtual int MaxElementSearchDepth
167166
{
168167
get { return Convert.ToInt32(UsedValues["MaxElementSearchDepth"]); }
169168
set { SetUsedValue("MaxElementSearchDepth", value); }
170169
}
171170

172-
public virtual bool RawElementBasedSearch
173-
{
174-
get { return Convert.ToBoolean(UsedValues["RawElementBasedSearch"]); }
175-
set { SetUsedValue("RawElementBasedSearch", value); }
176-
}
177-
178171
public virtual int DoubleClickInterval
179172
{
180173
get { return Convert.ToInt32(UsedValues["DoubleClickInterval"]); }
181174
set { SetUsedValue("DoubleClickInterval", value); }
182175
}
176+
177+
public virtual bool MoveMouseToGetStatusOfHourGlass
178+
{
179+
get { return Convert.ToBoolean(UsedValues["MoveMouseToGetStatusOfHourGlass"]); }
180+
set { SetUsedValue("MoveMouseToGetStatusOfHourGlass", value); }
181+
}
182+
183+
/// <summary>
184+
/// Implements <see cref="ICoreConfiguration.KeepOpenOnDispose"/>
185+
/// </summary>
186+
public virtual bool KeepOpenOnDispose
187+
{
188+
get { return Convert.ToBoolean(UsedValues["KeepOpenOnDispose"]); }
189+
set { SetUsedValue("KeepOpenOnDispose", value); }
190+
}
183191
}
184192
}

src/TestStack.White/Configuration/ICoreConfiguration.cs

+11-5
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ namespace TestStack.White.Configuration
1111
/// </summary>
1212
public interface ICoreConfiguration
1313
{
14+
ILoggerFactory LoggerFactory { get; set; }
15+
IDisposable ApplyTemporarySetting(Action<ICoreConfiguration> changes);
16+
IWaitHook AdditionalWaitHook { get; set; }
17+
DynamicProxyInterceptors Interceptors { get; }
18+
1419
/// <summary>
1520
/// In Milliseconds
1621
/// </summary>
1722
int BusyTimeout { get; set; }
1823
int FindWindowTimeout { get; set; }
1924
bool WaitBasedOnHourGlass { get; set; }
20-
DynamicProxyInterceptors Interceptors { get; }
2125
DirectoryInfo WorkSessionLocation { get; set; }
2226
int UIAutomationZeroWindowBugTimeout { get; set; }
2327
int PopupTimeout { get; set; }
@@ -28,12 +32,14 @@ public interface ICoreConfiguration
2832
int DragStepCount { get; set; }
2933
bool InProc { get; set; }
3034
bool ComboBoxItemsPopulatedWithoutDropDownOpen { get; set; }
31-
IWaitHook AdditionalWaitHook { get; set; }
32-
int MaxElementSearchDepth { get; set; }
3335
bool RawElementBasedSearch { get; set; }
36+
int MaxElementSearchDepth { get; set; }
3437
int DoubleClickInterval { get; set; }
3538
bool MoveMouseToGetStatusOfHourGlass { get; set; }
36-
ILoggerFactory LoggerFactory { get; set; }
37-
IDisposable ApplyTemporarySetting(Action<ICoreConfiguration> changes);
39+
/// <summary>
40+
/// Flag to allow keeping the <see cref="TestStack.White.Application"/> and <see cref="TestStack.White.UIItems.WindowItems.Window" />
41+
/// open after White has disposed it's objects.
42+
/// </summary>
43+
bool KeepOpenOnDispose { get;set;}
3844
}
3945
}

src/TestStack.White/UIItems/WindowItems/Window.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,10 @@ public override string ToString()
365365

366366
public virtual void Dispose()
367367
{
368-
Close();
368+
if (!CoreAppXmlConfiguration.Instance.KeepOpenOnDispose)
369+
{
370+
Close();
371+
}
369372
}
370373

371374
/// <summary>

0 commit comments

Comments
 (0)