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 static TestObjectNurse BuildTestObjectsHierarchy(List <AutomationElement> ancestorElements, BreadcrumbControl breadcrumbControl, LAPListViewControl listView, Bitmap bmpDeskTop ) { int ancestorCount = ancestorElements.Count; int breadcrumbCount = breadcrumbControl.Count; int indexOfAutomationElement = 0; UIATestObject topTestObject = UIAUtility.CreateTestObject(ancestorElements[0]); TestObjectNurse topNurseObject = new TestObjectNurse(topTestObject); TestObjectNurse currentNurseObject = topNurseObject; if (ancestorCount > breadcrumbCount) { for (indexOfAutomationElement = 1; indexOfAutomationElement < ancestorCount && breadcrumbCount < ancestorCount - indexOfAutomationElement; ++indexOfAutomationElement) { AutomationElement element = ancestorElements[indexOfAutomationElement]; if (!string.IsNullOrEmpty(element.Current.Name)) { UIATestObject childTestObject = UIAUtility.CreateTestObject(element); currentNurseObject = (TestObjectNurse)currentNurseObject.AddChild(childTestObject); } } } Breadcrumb[] breadcrumbs = breadcrumbControl.GetItems(); foreach (Breadcrumb breadcrumb in breadcrumbs) { if (breadcrumb.Checked) { UIATestObject childTestObject = UIAUtility.CreateTestObject((breadcrumb.Tag as ElementProperties).AutomationElement); currentNurseObject = (TestObjectNurse)currentNurseObject.AddChild(childTestObject); } } ListView.CheckedListViewItemCollection selectedItems = listView.CheckedItems; foreach (ListViewItem item in selectedItems) { if (null == item.Tag) { continue; } ElementProperties ep = item.Tag as ElementProperties; TestObjectNurse subNurse = ep.ToNurseObject(); subNurse.ImageFile = SnapshotHelper.SnapshotFileFromBitmap(subNurse.TestObject, bmpDeskTop); currentNurseObject.AddChild(subNurse); } return(topNurseObject); }
private void lvObjects_SelectedIndexChanged(object sender, EventArgs e) { // Acquire SelectedItems reference. var selectedItems = this.lapListViewObjects.SelectedItems; if (selectedItems.Count > 0) { // Display text of first item selected. ElementProperties elementProperties = (ElementProperties)selectedItems[0].Tag; propertiesListview.FillListviewWithProperties(elementProperties); MemoryStream stream = SnapshotHelper.SnapshotFromBitmap(elementProperties.AutomationElement, _bmpDeskTop); if (stream == null) { return; } pictureBox1.Image = Image.FromStream(stream); } this.lapListViewObjects.Invalidate(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(); }