Beispiel #1
0
        /// <summary>
        /// Runs the login test.
        /// </summary>
        public bool Login()
        {
            try
            {
                // Looks for and invoke the login button.
                AutomationElement node = GetAnchor2(true);
                ViewTree.RetrieveChildNodePatternByCondition(ref node, new Condition[] { new PropertyCondition(AutomationElement.AutomationIdProperty, "LoginButton") }, true, Pattern.Invoke);

                // Enters the email address.
                node = GetAnchor2();
                ViewTree.RetrieveChildNodePatternByCondition(ref node, new Condition[] { new PropertyCondition(AutomationElement.AutomationIdProperty, "EmailTextBox") }, true, Pattern.Value, user);

                // Enters the password.
                node = GetAnchor2();
                ViewTree.RetrieveChildNodePatternByCondition(ref node, new Condition[] { new PropertyCondition(AutomationElement.AutomationIdProperty, "PasswordBox") }, true, Pattern.Value, password);

                // Before sending login credentials to the server, we must first subscribe to the structucture changed event at the level of anchor #1.
                // When login is completed, the children of this node change and this way we detect our test is successful.
                node = GetAnchor1();
                Automation.AddStructureChangedEventHandler(node, TreeScope.Children, structureChangedEventHandler);

                // Looks for and invoke the sign in button.
                node = GetAnchor2();
                ViewTree.RetrieveChildNodePatternByCondition(ref node, new Condition[] { new PropertyCondition(AutomationElement.AutomationIdProperty, "SignInButton") }, true, Pattern.Invoke);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #2
0
        /// <summary>
        /// In the login window, gets the parent node of main form, from which we can search controls.
        /// </summary>
        /// <param name="setFocus">Whether we must bring the login window to the foreground or not.</param>
        private AutomationElement GetAnchor2(bool setFocus = false)
        {
            AutomationElement node = GetAnchor1(setFocus);

            ViewTree.RetrieveChildNodePatternByCondition(ref node, new Condition[] { new PropertyCondition(AutomationElement.ClassNameProperty, "Windows.UI.Core.CoreWindow") });
            ViewTree.RetrieveChildNodePatternByCondition(ref node, new Condition[] { new PropertyCondition(AutomationElement.ClassNameProperty, "ScrollViewer") });
            return(node);
        }
Beispiel #3
0
        /// <summary>
        /// In the login window, gets the parent's parent node of main form, from which we can search controls.
        /// </summary>
        /// <param name="setFocus">Whether we must bring the login window to the foreground or not.</param>
        private AutomationElement GetAnchor1(bool setFocus = false)
        {
            // Retrieves login window.
            AutomationElement node = AutomationElement.RootElement;

            ViewTree.RetrieveChildNodePatternByCondition(ref node, new Condition[] { new PropertyCondition(AutomationElement.NameProperty, "Wunderlist") });

            // Brings login window to the foreground when "setFocus" is true.
            if (setFocus)
            {
                ViewTree.Focus(node);
            }

            return(node);
        }