예제 #1
0
        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);
        }
예제 #2
0
        public static MessageBoxProxy WaitMessageBox(this AutomationElement element, Action action, Func <string> actionDescription = null, int?timeOut = null)
        {
            if (actionDescription == null)
            {
                actionDescription = () => "Get MessageBox after";
            }

            var pid      = element.Current.ProcessId;
            var previous = WaitExtensions.GetAllProcessWindows(pid).Select(a => a.GetRuntimeId().ToString(".")).ToHashSet();

            action();

            AutomationElement newWindow = null;

            element.Wait(() =>
            {
                newWindow = WaitExtensions.GetAllProcessWindows(pid).FirstOrDefault(a => !previous.Contains(a.GetRuntimeId().ToString(".")));

                return(newWindow != null);
            }, actionDescription, timeOut);

            return(new MessageBoxProxy(newWindow));
        }