Exemple #1
0
        private Stack <int> ToIndexStack(IXPathNode node)
        {
            XPathAdapter          adapter = node as XPathAdapter;
            XPathAttributeAdapter attr    = node as XPathAttributeAdapter;

            if (attr != null)
            {
                adapter = attr.Owner;
            }

            if (adapter != null)
            {
                UIAControl  control = adapter.Owner;
                Stack <int> result  = new Stack <int>();

                do
                {
                    result.Push(control.Index);
                    control = (UIAControl)control.Parent;
                } while(control != null);

                return(result);
            }

            throw new ArgumentException("Trying to sort a node I don't know.");
        }
Exemple #2
0
        private void HandleTimerTick(object sender, EventArgs e)
        {
            // Simulate a mouse move over this point to activate any important mouseover behaviors
            System.Windows.Point point = new System.Windows.Point(Cursor.Position.X, Cursor.Position.Y);

            AutomationElement element = null;

            try {
                element = AutomationElement.FromPoint(new System.Windows.Point(Cursor.Position.X, Cursor.Position.Y));
            }
            catch {
            }

            if (element != null)
            {
                /*if( !element.Equals( capturedElement ) )
                 *      GDI32.RedrawWindow(capturedElement);*/

                UIControlBase control = UIAControl.GetControlByType(element);

                if (control != null)
                {
                    Debug.WriteLine("Sending MOUSEMOVE");
                    System.Windows.Point clientPoint = new System.Windows.Point((int)(Cursor.Position.X - control.Layout.X), (int)(Cursor.Position.Y - control.Layout.Y));

                    SendMessage(new HandleRef(this, control.Handle), 0x0200, (IntPtr)0, (IntPtr)(((int)clientPoint.Y << 16) | (int)clientPoint.X));
                }

                Debug.WriteLine("Repainting highlight after MOUSEMOVE");
                GDI32.HighlightWindow(capturedElement);
            }

            RecaptureElement(point, true);
        }
Exemple #3
0
        private void nodeContextMenu_Opening(object sender, CancelEventArgs e)
        {
            TreeNode node = treeView.SelectedNode;

            if (node != null && node.Tag is UIAControl)
            {
                UIAControl control = node.Tag as UIAControl;
                winFormsToolStripMenuItem.Enabled = control.IsWinForms;
            }
        }
Exemple #4
0
        private void winFormsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode node = treeView.SelectedNode;

            if (node != null && node.Tag is UIAControl)
            {
                UIAControl control = node.Tag as UIAControl;
                control.GetWinFormsProperties();
                TrackSelection(control);
            }
        }
Exemple #5
0
        public override void Body()
        {
            ActualResult = TestCaseResult.Failed;

            Stopwatch     watch         = new Stopwatch();
            string        lastException = null;
            UIControlBase c             = null;

            watch.Start();
            while (watch.ElapsedMilliseconds < _timeout + 10)
            {
                try
                {
                    c = UIControlBase.FindControlByPath(_control);

                    if (c.Exists)
                    {
                        break;
                    }
                }
                catch (Exception ex) {
                    lastException = ex.ToString();
                }
            }

            if (c == null || !c.Exists)
            {
                Log.Error("Control not found after " + _timeout + " milliseconds", _control);

                if (lastException != null)
                {
                    Log.Warning("Exception caught", lastException, EntryVerbosity.Debug);
                }

                return;
            }

            UIAControl uia = c as UIAControl;

            if (uia != null && uia.XPathElementName == "titlebar")
            {
                // Go with the parent
                c = uia.Parent;
            }

            c.SetFocus();
            ActualResult = TestCaseResult.Passed;
        }
Exemple #6
0
        private void ShowCapturedElement()
        {
            if (capturedElement == null)
            {
                return;
            }

            UIControlBase control = null;

            if (radioButtonWeb.Checked)
            {
                control = Desktop.Web.GetControlFromCursor();
            }
            else
            {
                control = UIAControl.GetControlByType(capturedElement);
            }
            if (control != null)
            {
                textBox.Text   = control.CodePath;
                coordinate     = new System.Windows.Point((int)(Cursor.Position.X - control.Layout.X), (int)(Cursor.Position.Y - control.Layout.Y));
                textBoxXY.Text = coordinate.ToString();

                _controlPropertyGrid.SelectedObject = null;

                _hierarchyList.BeginUpdate();
                _hierarchyList.Items.Clear();

                UIControlBase pass = control;

                while (pass != null)
                {
                    _hierarchyList.Items.Add(new ListViewItem()
                    {
                        Text = pass.VisibleName,
                        Tag  = pass
                    });

                    pass = pass.Parent;
                }

                _hierarchyList.EndUpdate();
                _hierarchyList.Items[0].Selected = true;
            }
        }
Exemple #7
0
 public UIControlBase GetFocusedElement()
 {
     return(UIAControl.GetControlByType(AutomationElement.FocusedElement));
 }
Exemple #8
0
 public XPathAdapter(UIAControl owner, TextWriter log)
 {
     _owner = owner;
     _log   = log;
 }
Exemple #9
0
 /// <summary>
 /// Set focus on current page.
 /// </summary>
 /// <example>
 /// <code>
 ///   Desktop.Web.CurrentPage.Navigate("www.amazon.com");
 ///   bool pageFound = Desktop.Web.WaitForPage("amazon", 30,true);
 ///    if (pageFound)
 ///		   Desktop.Web.CurrentPage.SetFocus();
 /// </code>
 /// </example>
 public override void SetFocus()
 {
     UIAControl.GetControlByType(uiaElement).SetFocus();
     docInstance.focus();
 }
 public static T GetControl <T>(this UIAControl parent, Identifier identifier)
 {
     return((T)(object)parent.Find(System.Windows.Automation.TreeScope.Children, identifier.GetProperties(), identifier.GetValues()));
 }