public static AutomationElement CaptureWindow(this AutomationElement element, Action action, Func <string> actionDescription = null, int?timeOut = null, Func <AutomationElement, bool> windowsCondition = null) { if (actionDescription == null) { actionDescription = () => "Get Windows after"; } var pid = element.Current.ProcessId; int c = 0; var previous = GetAllProcessWindows(pid, c).Select(a => a.GetRuntimeId().ToString(".")).ToHashSet(); c++; action(); AutomationElement newWindow = null; element.Wait(() => { newWindow = GetAllProcessWindows(pid, c).FirstOrDefault(a => !previous.Contains(a.GetRuntimeId().ToString(".")) && (windowsCondition == null || windowsCondition(a))); c++; MessageBoxProxy.ThrowIfError(newWindow); if (newWindow != null) { return(true); } return(false); }, actionDescription, timeOut ?? CapturaWindowTimeout); return(newWindow); }
AutomationElement LoginCapture(string userName, string password, int?timeOut = null) { Element.ChildById("tbUserName").Value(userName); Element.ChildById("tbPassword").Value(password); var pid = Element.Current.ProcessId; var previous = WaitExtensions.GetAllProcessWindows(pid).Select(a => a.GetRuntimeId().ToString(".")).ToHashSet(); Element.ChildById("btLogin").ButtonInvoke(); var error = Element.ChildById("txtError"); AutomationElement newWindow = null; Element.Wait(() => { newWindow = WaitExtensions.GetAllProcessWindows(pid).FirstOrDefault(a => !previous.Contains(a.GetRuntimeId().ToString("."))); MessageBoxProxy.ThrowIfError(newWindow); if (newWindow != null) { return(true); } if (!error.Current.IsOffscreen && error.Current.Name.HasText()) { throw new MessageBoxErrorException("LoginWindow: " + error.Current.Name); } return(false); }, () => "Waiting for login", timeOut ?? WaitExtensions.CapturaWindowTimeout); return(newWindow); }
public static void ThrowIfError(AutomationElement windowElement) { if (windowElement != null && IsMessageBox(windowElement)) { var mb = new MessageBoxProxy(windowElement); mb.ThrowIfError(); } }
public static void ThrowIfError(AutomationElement windowElement) { if (windowElement != null && IsMessageBox(windowElement)) { var mb = new MessageBoxProxy(windowElement); mb.ThrowIfError(); } }
public override void Dispose() { try { if (base.Close()) { MessageBoxProxy confirmation = null; Element.Wait(() => { try { if (IsClosed) { return(true); } confirmation = Element.TryMessageBoxChild(); if (confirmation != null) { return(true); } base.Close(); return(false); } catch (ElementNotAvailableException) { return(true); } }, () => "Waiting for normal window to close or show confirmation dialog"); if (confirmation != null && !confirmation.IsError) { confirmation.OkButton.ButtonInvoke(); } } OnDisposed(); } catch { if (CurrentException == null) { throw; } } }
public void Ok() { var entityId = EntityId; ButtonBar.OkButton.ButtonInvoke(); Element.Wait( () => { var childWindows = Element.TryChild(a => a.Current.ControlType == ControlType.Window); if (childWindows != null) { MessageBoxProxy.ThrowIfError(childWindows); throw new InvalidOperationException("A window ({0})was open after pressing Ok on {1}. Consider using OkCapture".FormatWith(WaitExtensions.NiceToString(childWindows), entityId)); } return(IsClosed); }, actionDescription: () => "Waiting to close window after OK {0}".FormatWith(entityId)); }
public static AutomationElement CaptureChildWindow(this AutomationElement element, Action action, Func <string> actionDescription = null, int?timeOut = null) { if (actionDescription == null) { actionDescription = () => "Get Windows after"; } var parentWindow = WindowProxy.Normalize(element); var previous = parentWindow.Children(a => a.Current.ControlType == ControlType.Window).Select(a => a.GetRuntimeId().ToString(".")).ToHashSet(); action(); AutomationElement newWindow = null; List <AutomationElement> currentWindows = new List <AutomationElement>(); element.Wait(() => { currentWindows = parentWindow.Children(a => a.Current.ControlType == ControlType.Window); newWindow = currentWindows.FirstOrDefault(a => !previous.Contains(a.GetRuntimeId().ToString("."))); MessageBoxProxy.ThrowIfError(newWindow); if (newWindow != null) { return(true); } return(false); }, () => actionDescription() + "\r\n\tcurrentWindows: " + currentWindows.ToString(a => NiceToString(a), "\r\n\t\t") + "\r\n\tnewWindow: " + NiceToString(newWindow) + "\r\n\tprevious: " + previous.ToString(a => a, " ") , timeOut ?? CapturaWindowTimeout); return(newWindow); }
public static void WaitDataContextChangedAfter(this AutomationElement element, Action action, int?timeOut = null, Func <string> actionDescription = null) { string oldValue = element.Current.ItemStatus; if (string.IsNullOrEmpty(oldValue)) { throw new InvalidOperationException("Element does not has ItemStatus set. Consider setting m:Common.AutomationItemStatusFromDataContext on the WPF control"); } var pid = element.Current.ProcessId; int c = 0; var previous = GetAllProcessWindows(pid, c).Select(a => a.GetRuntimeId().ToString(".")).ToHashSet(); c++; action(); if (actionDescription == null) { actionDescription = () => "DataContextChanged for {0}".FormatWith(oldValue); } element.Wait(() => { var newValue = element.Current.ItemStatus; if (newValue != null && newValue != oldValue) { return(true); } var newWindow = GetAllProcessWindows(pid, c).FirstOrDefault(a => !previous.Contains(a.GetRuntimeId().ToString("."))); c++; MessageBoxProxy.ThrowIfError(newWindow); return(false); }, actionDescription, timeOut); }