Esempio n. 1
0
        public void CaptureSnapshot(TestObjectNurse nurseObject)
        {
            string token = null;

            UIATestObject testObject = nurseObject.TestObject as UIATestObject;

            if (testObject == null)
            {
                return;                     //not the UIA object
            }
            AutomationElement element = testObject.AutomationElement;

            if (SpySettings.CaptureSnapshots)
            {
                try
                {
                    //capture snapshot of clicked area
                    SnapshotHelper.CaptureTempSnapshot(element, out token);
                }
                catch (ElementNotAvailableException)
                {
                    MessageBox.Show(StringResources.LPSpy_SpyMainWindow_CannotFindObjectMsg);
                }
                catch (ApplicationException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            nurseObject.ImageFile = SnapshotHelper.GetCachedSnapshot(token, nurseObject.ImageFile);


            AppEnvironment.SetModelChanged(true);
        }
        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);
            }
        }
        private void btnAddObject_Click(object sender, EventArgs e)
        {
            this.Visible        = false;
            this._owner.Visible = true;

            if (this._modeType == AddObjWndModeType.Normal && this.UpdateSelectedTree != null)
            {
                TestObjectNurse selfNurse = GetNurseObjectsLine(objectTree);

                TestObjectNurse leftNurse = null, rightNurse = null;

                if (_leftElement != null)
                {
                    TreeNode node = _leftElement.GetContext <TreeNode>();
                    if (node.Checked)
                    {
                        leftNurse = _leftElement.ToNurseObject();
                    }
                }
                if (_rightElement != null)
                {
                    TreeNode node = _rightElement.GetContext <TreeNode>();
                    if (node.Checked)
                    {
                        rightNurse = _rightElement.ToNurseObject();
                    }
                }

                selfNurse.ImageFile = SnapshotHelper.GetCachedSnapshot(_token);

                TestObjectNurse rootNurse;
                TestObjectNurse temp;
                temp = selfNurse;
                do
                {
                    rootNurse = temp;
                    temp      = rootNurse.ParentNurse;
                } while (temp != null);

                UpdateSelectedTree(rootNurse, selfNurse, leftNurse, rightNurse);
            }

            if (this._modeType == AddObjWndModeType.UpdateProperties && this.UpdateSelectedNode != null)
            {
                ElementProperties elementProperties = null;
                if (this.objectTree.SelectedNode != null &&
                    null != (elementProperties = objectTree.SelectedNode.Tag as ElementProperties))
                {
                    if (SpySettings.CaptureSnapshots)
                    {
                        //capture snapshot of clicked area
                        SnapshotHelper.CaptureTempSnapshot(elementProperties.AutomationElement, out _token);
                    }
                    UpdateSelectedNode(elementProperties, SnapshotHelper.GetCachedSnapshot(_token));
                }
                else
                {
                    UpdateSelectedNode(_selfElement, SnapshotHelper.GetCachedSnapshot(_token));
                }
            }


            this.Dispose();
        }