예제 #1
0
        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);
        }
        public void ElementProperties_ToNurseObject2()
        {
            Dictionary <string, string> properties = new Dictionary <string, string>()
            {
                { UIAControlKeys.AutomationId, "myId" },
                { UIAControlKeys.AccessKey, "" },
                { UIAControlKeys.ClassName, "CalcClass" }
            };

            ElementProperties element = new ElementProperties(properties);

            LPReplayCore.TestObjectNurse nurseObject = element.ToNurseObject();

            UIATestObject testObject = (UIATestObject)nurseObject.TestObject;

            Assert.AreEqual(2, testObject.Properties.Count);        //only 3 recommended properties;

            Assert.AreEqual(2, nurseObject.CachedProperties.Count); //only cached non-empty properties

            Assert.AreEqual(element.DerivedName, testObject.NodeName);
        }
        public void ElementProperties_ToNurseObject()
        {
            Dictionary <string, string> properties = new Dictionary <string, string>()
            {
                { UIAControlKeys.Name, "myName" },
                { UIAControlKeys.AutomationId, "myId" },
                { UIAControlKeys.ClassName, "myClass" },
                { UIAControlKeys.HelpText, "myHelpText" },
                { UIAControlKeys.AccessKey, "" },
                { UIAControlKeys.Type, "Button" }
            };

            ElementProperties element = new ElementProperties(properties);

            LPReplayCore.TestObjectNurse nurseObject = element.ToNurseObject();

            UIATestObject testObject = (UIATestObject)nurseObject.TestObject;

            Assert.AreEqual(3, testObject.Properties.Count);        //only 3 recommended properties;

            Assert.AreEqual(4, nurseObject.CachedProperties.Count); //There are suppose 4 cached properties;

            Assert.AreEqual(element.DerivedName, testObject.NodeName);
        }
예제 #4
0
        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();
        }