public void UIAHighlight_SearchandHighlight_UIA()
        {
            UIATestObject testObject = descriptor.GetObject() as UIATestObject;

            bool result = UIAHighlight.SearchAndHighlight(testObject);

            Assert.IsTrue(result);
        }
 private void HighlightObjectThread()
 {
     UIATestObject testObject = (UIATestObject)_condition.TestObject;
     if (!UIAHighlight.SearchAndHighlight(testObject))
     {
         MessageBox.Show(StringResources.LPSpy_SpyMainWindow_CannotFindObjectMsg);
     }
 }
Esempio n. 3
0
 private void btnHighlight_Click(object sender, EventArgs e)
 {
     try
     {
         UIAHighlight.HighlightThread_Spy((AutomationElement)treeObjects.SelectedNode.Tag);
     }
     catch
     { }
 }
Esempio n. 4
0
        private void btnHighlight_Click(object sender, EventArgs e)
        {
            if (virtualControlListView1.SelectedItems.Count == 0)
            {
                return;
            }
            VirtualTestObject testObject = (VirtualTestObject)virtualControlListView1.SelectedItems[0].Tag;

            UIAHighlight.HighlightVirtualControl(_parentControl.AutomationElement, testObject.BoundingRect);
        }
Esempio n. 5
0
        public void HighlightWebElement(RemoteWebElement webElement)
        {
            if (webElement == null)
            {
                return;
            }
            int       X  = webElement.Location.X + (int)_toobarAutoElement.Current.BoundingRectangle.TopLeft.X;
            int       Y  = webElement.Location.Y + (int)_toobarAutoElement.Current.BoundingRectangle.TopLeft.Y + (int)_toobarAutoElement.Current.BoundingRectangle.Height;
            Rectangle rc = new Rectangle(X, Y, webElement.Size.Width, webElement.Size.Height);

            UIAHighlight.HighlightRect(rc);
        }
        public void UIAHighlight_SearchandHighlight_ProgramRestarted()
        {
            UIATestObject testObject = descriptor.GetObject() as UIATestObject;

            AutomationElement firstElement = testObject.AutomationElement;

            //close and start another calculator
            TestUtility.ExitQTCalculator();
            TestUtility.LaunchQTCalculator();

            //this should also succeed
            bool result = UIAHighlight.SearchAndHighlight(testObject);

            Assert.IsTrue(result);
        }
        public void Click()
        {
            Assert.IsTrue(this.Parent != null);
            UIATestObject parentObject = (UIATestObject)this.Parent;

            Rect?tempRect = UIAHighlight.HighlightVirtualControl(parentObject.AutomationElement, this.BoundingRect);

            if (tempRect == null)
            {
                return;
            }

            Rect rect = (Rect)tempRect;

            ClickOnPointTool.ClickOnPoint((IntPtr)null, new System.Windows.Point(rect.Left + 10, rect.Top + 10));
            //InvokePattern invokePattern = (InvokePattern)parentObject.AutomationElement.GetCurrentPattern(InvokePattern.Pattern);
        }
        public void UIAHighlight_SearchandHighlight_Virtual()
        {
            UIATestObject testObject = descriptor.GetObject() as UIATestObject;

            VirtualTestObject virtualButton7 = new VirtualTestObject("button7", new Rect(76, 139, 34, 34));
            VirtualTestObject virtualButton4 = new VirtualTestObject("button4", new Rect(74, 177, 36, 40));

            testObject.AddChild(virtualButton7);
            testObject.AddChild(virtualButton4);


            //this should also succeed
            bool result = UIAHighlight.SearchAndHighlight(virtualButton7);

            Assert.IsTrue(result);
            result = UIAHighlight.SearchAndHighlight(virtualButton4);
            Assert.IsTrue(result);
        }
Esempio n. 9
0
        public void LPSpy_HighlightTest()
        {
            AutomationElement element = TestUtility.GetCalculatorButton1Element();

            Assert.AreNotEqual(null, element, "Cannot find the element to highlight");

            DateTime begin = DateTime.Now;

            UIAHighlight.HighlightAutomationElement(element);
            DateTime end = DateTime.Now;

            long tickCount = end.Ticks - begin.Ticks;

            double seconds = (double)tickCount / 10000000;

            Assert.IsTrue(seconds >= 1,
                          string.Format("Should need at least 1 second to highlight the element, the actual time is {0}", seconds));
        }
Esempio n. 10
0
        public void PointToElements(Point point)
        {
            AutomationElementCollection aeCollection = null;
            AutomationElement           menuAe       = null;

            using (_generalCacheReq.Activate())
            {
                _element = AutomationElement.FromPoint(point);
                UIAHighlight.HighlightThread_Spy(_element);

                if (_element.Current.ControlType == ControlType.MenuItem)
                {
                    if (UIAUtility.ExpandMenuItem(_element) && _element.FindFirst(TreeScope.Children, _propertyMenuItemCondition) == null)
                    {
                        menuAe = RetrieveMenuElement(_element);
                    }
                }

                if (menuAe == null)
                {
                    if (_element.FindFirst(TreeScope.Children, Condition.TrueCondition) == null)
                    {
                        _element = TreeWalker.ControlViewWalker.GetParent(_element);
                    }
                    aeCollection = _element.FindAll(TreeScope.Children, Condition.TrueCondition);
                }
                else
                {
                    aeCollection = menuAe.FindAll(TreeScope.Descendants, _menuCondition);
                }
                _ancestorElements.Clear();
                _ancestorElements = UIAUtility.GetAutomationElementsLine(_element);
                _childElements.Clear();
                _childElements = aeCollection.Cast <AutomationElement>().ToList();
            }
            Console.WriteLine("childrenelement count {0}, ancestorelement count {1}", _childElements.Count, _ancestorElements.Count);
            if (null != afterPointToElementsEventHander)
            {
                ElementsBuilderEventArgs e = new ElementsBuilderEventArgs(this, _ancestorElements, _childElements, _element);
                afterPointToElementsEventHander(this, e);
            }
        }
Esempio n. 11
0
        private void ConstructElementsTree(AutomationElement clickedElement)
        {
            this.objectTree.Nodes.Clear();

            if (clickedElement == null)
            {
                return;
            }

            UIAHighlight.HighlightThread_Spy(clickedElement);

            List <AutomationElement> elements = UIAUtility.GetAutomationElementsLine(clickedElement);

            TreeNodesFromAutomationElements(elements);

            if (_modeType == AddObjWndModeType.Normal)
            {
                ConstructLeftAndRightNode(objectTree, clickedElement);
            }

            this.objectTree.ExpandAll();
        }
Esempio n. 12
0
        private void UpdateElementData(System.Windows.Point mousePoint, bool clicked)
        {
            _parentsList.Clear();

            AutomationElement hoveredElement = null;

            //need to use the Async method to get the object
            Utility.AsyncCall(() => {
                try
                {
                    hoveredElement = AutomationElement.FromPoint(mousePoint);
                    if (hoveredElement != null)
                    {
                        _elementProperties = new ElementProperties(hoveredElement);
                    }
                }
                catch (FileNotFoundException ex /*TODO fake exception, should be replaced with real one*/)
                {
                    _Logger.WriteLog(ex.Message.ToString());
                    _Logger.WriteLog(ex.Source);
                    _Logger.WriteLog(ex.TargetSite.ToString());
                    if (ex.InnerException != null)
                    {
                        _Logger.WriteLog(ex.InnerException.Message);
                    }
                }
            });

            if (hoveredElement != null & hoveredElement != _prevousElement)
            {
                _prevousElement = hoveredElement;

                HighlightRectangle hightlightRect = UIAHighlight.HighlightThread_Spy(hoveredElement, infinite: true);

                if (clicked || _alwaysOnTop)
                {
                    if (clicked)
                    {
                        if (hightlightRect != null)
                        {
                            hightlightRect.Visible = false;
                            Thread.Sleep(500);
                        }
                    }
                    this.Invoke(new Action(() =>
                    {
                        _leftElement  = UIAUtility.GetPreviousElement(hoveredElement);
                        _rightElement = UIAUtility.GetNextElement(hoveredElement);
                        _parentsList  = UIAUtility.GetAutomationElementsLine(hoveredElement);

                        /*
                         * AutomationElement rootElement = AutomationElement.RootElement;
                         * while (parent != null)
                         * {
                         *  if (!(parent.Current.NativeWindowHandle == rootElement.Current.NativeWindowHandle && rootElement.Current.Name == parent.Current.Name))
                         *  {
                         *      parentsList.Add(parent);
                         *  }
                         *  parent = TreeWalker.ControlViewWalker.GetParent(parent);
                         * }
                         *
                         * parentsList.Reverse();
                         */
                        this.treeObjects.Nodes.Clear();

                        TreeNodeCollection currentTreeNodeCollection = this.treeObjects.Nodes;
                        TreeNode currentTreeNode = null;
                        foreach (AutomationElement element in _parentsList)
                        {
                            currentTreeNode           = currentTreeNodeCollection.Add(_parentsList.IndexOf(element).ToString(), element.Current.ControlType.ControlTypeToString() + ": " + element.Current.Name);
                            currentTreeNode.Tag       = element;
                            currentTreeNodeCollection = currentTreeNode.Nodes;
                        }

                        if (_leftElement != null)
                        {
                            currentTreeNode     = currentTreeNodeCollection.Add("left", "[Left Object]" + _leftElement.Current.ControlType.ControlTypeToString() + ": " + _leftElement.Current.Name);
                            currentTreeNode.Tag = _leftElement;
                        }

                        currentTreeNode = currentTreeNodeCollection.Add("self", hoveredElement.Current.ControlType.ControlTypeToString() + ": " + hoveredElement.Current.Name);
                        this.treeObjects.SelectedNode = currentTreeNode;
                        currentTreeNode.Tag           = hoveredElement;

                        if (_rightElement != null)
                        {
                            currentTreeNode     = currentTreeNodeCollection.Add("right", "[Right Object]" + _rightElement.Current.ControlType.ControlTypeToString() + ": " + _rightElement.Current.Name);
                            currentTreeNode.Tag = _rightElement;
                        }
                        this.treeObjects.ExpandAll();
                        updatePropertyTable(hoveredElement);
                    }));
                }
            }
        }
Esempio n. 13
0
 public void UIAHighlight_HighlightRectangle()
 {
     UIAHighlight.HighlightRect(new Rect(0, 0, 100, 200), Color.Green);
 }
Esempio n. 14
0
 public void UIAHighlight_HighlightVirtualControl()
 {
     UIAHighlight.HighlightRect(new Rect(0, 0, 100, 200), Color.Green);
 }
Esempio n. 15
0
        private void PointToSpiedData(Point mousePoint)
        {
            try
            {
                AutomationElement clickedElement = AutomationElement.FromPoint(mousePoint);

                WebDriverHost webDriverHost = this.Tag as WebDriverHost;
                if (null != webDriverHost && clickedElement.Current.ClassName.Equals("Chrome_RenderWidgetHostHWND"))
                {
                    System.Drawing.Point point = new System.Drawing.Point((int)mousePoint.X, (int)mousePoint.Y);
                    webDriverHost.CheckWindowHandle(clickedElement);

                    // RemoteWebElement webElement = webDriverHost.FindElementByPoint(point) as RemoteWebElement;

                    /* if (SpySettings.CaptureSnapshots && null != webElement)
                     * {
                     *   //capture snapshot of clicked area
                     *   SnapshotHelper.CaptureTempSnapshot(webElement, out _token);
                     * }*/
                    //  WebUtility.GetElementScreenRect(webElement);
                    // UIAHighlight.HighlightRect( WebUtility.GetElementScreenRect(webElement));
                    //     webDriverHost.HighlightWebElement(webElement);
                    //     ConstructElementsTree(webElement);

                    /* List<RemoteWebElement> webElements = webDriverHost.GenerateElementsLineByPoint(point);
                     *
                     * TreeNodesFromAutomationElements(webElements);*/
                    System.Drawing.Rectangle    rect = System.Drawing.Rectangle.Empty;
                    List <WebElementProperties> webElementProperiesList = webDriverHost.GenerateElementPropertiesLineByPoint(point);
                    if (webElementProperiesList.Count > 0)
                    {
                        WebElementProperties webElementProperties = webElementProperiesList[webElementProperiesList.Count - 1];
                        rect = webDriverHost.GetElementRectangle(webElementProperties);
                        UIAHighlight.HighlightRect(rect);
                    }
                    TreeNodesFromWebElementProperties(webDriverHost.GenerateElementPropertiesLineByPoint(point));
                    //webDriverHost.GetElementRectangle()
                    // UIAHighlight.HighlightRect(WebUtility.GetElementScreenRect(webDriverHost.WebSelectElement));
                    if (SpySettings.CaptureSnapshots && !rect.IsEmpty)
                    {
                        //capture snapshot of clicked area

                        SnapshotHelper.CaptureTempSnapshot(rect, out _token);
                    }


                    this.objectTree.ExpandAll();
                    return;
                }



                ConstructElementsTree(clickedElement);

                _token = null;

                if (SpySettings.CaptureSnapshots)
                {
                    //capture snapshot of clicked area
                    SnapshotHelper.CaptureTempSnapshot(clickedElement, out _token);
                }
            }
            catch (ElementNotAvailableException)
            {
                //Element is no longer available, please reselect the element
                MessageBox.Show(StringResources.LPSpy_ElementNotAvailableException);
            }
        }
Esempio n. 16
0
        private void HighlightObjectThread(object param)
        {
            try
            {
                TestObjectNurse nurseObject = param as TestObjectNurse;
                if (nurseObject == null)
                {
                    return;
                }

                ITestObject testObject = nurseObject.TestObject;

                SetStatusText(StringResources.LPSpy_SpyMainWindow_Identifying);


                //Check whether the WebDriver Host exist or not
                if (testObject.ControlTypeString.StartsWith("Web"))
                {
                    SETestObject seTestObject = testObject as SETestObject;
                    if (seTestObject.SEWebElement == null)
                    {
                        //look for WebPage
                        TreeNode    parentNode   = nurseObject.TreeNode;
                        ITestObject parentObject = null;


                        do
                        {
                            parentObject = TestObjectNurse.FromTreeNode(parentNode).TestObject;
                            if (parentObject.ControlTypeString.Equals("WebPage"))
                            {
                                //seTestObject = parentObject as SETestObject;
                                break;
                            }
                        }while (null != (parentNode = parentNode.Parent));

                        if (null != parentObject)
                        {
                            //check the WebDriverHost existing
                            if (null == _webDriverHost)
                            {
                                _webDriverHost = new WebDriverHost();
                                _webDriverHost.GotoUrl(parentObject.Properties[WebControlKeys.URL]);
                            }
                            else
                            {
                                _webDriverHost.SwithToURL(parentObject.Properties[WebControlKeys.URL]);
                            }
                            WebRefreshNodeTag(parentNode);
                        }
                    }

                    Rectangle rc = _webDriverHost.GetElementRectangle(seTestObject);

                    UIAHighlight.HighlightRect(rc);
                    return;
                }


                if (!UIAHighlight.SearchAndHighlight(testObject))
                {
                    MessageBox.Show(StringResources.LPSpy_SpyMainWindow_CannotFindObjectMsg);
                }
            }
            finally
            {
                SetStatusText("");
            }
        }
Esempio n. 17
0
        public void HighlightControl()
        {
            UIATestObject parentObject = (UIATestObject)this.Parent;

            UIAHighlight.HighlightVirtualControl(parentObject.AutomationElement, this.BoundingRect);
        }