Example #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);
        }
Example #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));
        }
Example #3
0
        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));
        }