private void TreeNodesFromAutomationElements(List <AutomationElement> elementsLine)
        {
            TreeNodeCollection currentNodes = this.objectTree.Nodes;
            TreeNode           tempNode     = null;

            int index = 0;

            foreach (AutomationElement element in elementsLine)
            {
                string controlType = element.Current.ControlType.ControlTypeToString();

                ElementProperties elementProperties = new ElementProperties(element);

                string displayName = controlType + ": " + elementProperties.DerivedName;
                tempNode     = currentNodes.Add(index.ToString(), displayName);
                tempNode.Tag = elementProperties;
                TreeNodeHelper.FixTreeNodeImage(tempNode, controlType);

                currentNodes = tempNode.Nodes;

                if (!string.IsNullOrEmpty(element.Current.Name))
                {
                    tempNode.Checked = true;
                }
            }

            TreeNode currentNode = tempNode;

            currentNode.Name        = "self";
            currentNode.Checked     = true;
            objectTree.SelectedNode = currentNode;

            _selfElement = (ElementProperties)currentNode.Tag;
        }
        private void TreeNodesFromAutomationElements(List <RemoteWebElement> webElements)
        {
            TreeNodeCollection currentNodes = this.objectTree.Nodes;
            TreeNode           tempNode     = null;

            int index = 0;

            foreach (RemoteWebElement webelement in webElements)
            {
                WebElementProperties webElementProperties = new WebElementProperties(webelement);
                if (string.IsNullOrEmpty(webElementProperties.ControlTypeString))
                {
                    continue;
                }
                tempNode     = currentNodes.Add(index.ToString(), webElementProperties.Name);
                tempNode.Tag = webElementProperties;
                TreeNodeHelper.FixTreeNodeImage(tempNode, "Button");
                currentNodes     = tempNode.Nodes;
                tempNode.Checked = true;
            }

            TreeNode currentNode = tempNode;

            currentNode.Name        = "self";
            currentNode.Checked     = true;
            objectTree.SelectedNode = currentNode;

            // _selfElement = (ElementProperties)currentNode.Tag;
        }
        private void TreeNodesFromWebElementProperties(List <WebElementProperties> webElementPropertiesList)
        {
            if (null == webElementPropertiesList || 0 == webElementPropertiesList.Count)
            {
                return;
            }
            TreeNodeCollection currentNodes = this.objectTree.Nodes;
            TreeNode           tempNode     = null;

            int index = 0;

            foreach (WebElementProperties webElementProperties in webElementPropertiesList)
            {
                tempNode     = currentNodes.Add(index.ToString(), webElementProperties.Name);
                tempNode.Tag = webElementProperties;
                TreeNodeHelper.FixTreeNodeImage(tempNode, "Custom");
                currentNodes     = tempNode.Nodes;
                tempNode.Checked = true;
            }

            TreeNode currentNode = tempNode;

            currentNode.Name        = "self";
            currentNode.Checked     = true;
            objectTree.SelectedNode = currentNode;
        }
        public void TreeNodeHelper_FixTreeImage()
        {
            TreeNode node = new TreeNode();

            TreeNodeHelper.FixTreeNodeImage(node, "Window");
            Assert.AreEqual(0, node.ImageIndex);

            TreeNodeHelper.FixTreeNodeImage(node, "ScrollBar");
            Assert.AreEqual(14, node.ImageIndex);

            TreeNodeHelper.FixTreeNodeImage(node, "SomethingElse");
            Assert.AreEqual((int)TreeNodeHelper.TreeNodeImage.Custom, node.ImageIndex);
        }
        /// <summary>
        /// generate tree nodes hierarchy from the TestObjects hierarchy
        /// </summary>
        /// <param name="testObjects"></param>
        /// <param name="parentNurse"></param>
        private static void TestObjectToTreeNode(IEnumerable <ITestObject> testObjects, TestObjectNurse parentNurse)
        {
            if (testObjects == null)
            {
                return;
            }

            foreach (ITestObject to in testObjects)
            {
                TestObjectNurse nurse    = (TestObjectNurse)parentNurse.AddChild(to);
                TreeNode        treeNode = nurse.TreeNode;
                treeNode.Expand();

                TreeNodeHelper.FixTreeNodeImage(treeNode, nurse.ControlTypeString);

                TestObjectToTreeNode(to.Children, nurse);
            }
        }
Esempio n. 6
0
        private bool MergeObjectsToMainTree(TestObjectNurse repoNurseNode, IEnumerable <ITestObject> testObjectNodes) //addCollection
        {
            bool found;
            bool changed = false;
            bool web     = false;

            foreach (TestObjectNurse testObjectNurse in testObjectNodes)
            {
                found = false;
                ITestObject testobject = testObjectNurse.TestObject;
                web = testobject.ControlTypeString.StartsWith("Web");

                //if ( null == (repoNurseNode.TestObject as UIATestObject ))
                //{

                //    TestObjectNurse newTestNurse = new TestObjectNurse(testObjectNurse.TestObject);

                //    newTestNurse.NodeName = testObjectNurse.TestObject.NodeName;

                //    repoNurseNode.AddChild(newTestNurse);

                //    TreeNode node = newTestNurse.TreeNode;

                //    changed = true;

                //    TreeNodeHelper.FixTreeNodeImage(node, "Button");

                //    MergeObjectsToMainTree(newTestNurse, testObjectNurse.Children);
                //   // NeighbourChecker(newTestNurse, testObjectNurse);

                //    RaiseMergeCompleteEvent(true);
                //    continue;
                //}
                ////UIACondition fromNodeCondition = (UIACondition)fromNode.Tag;
                TestObjectNurse repoNode = FindMatchingNode(repoNurseNode, testObjectNurse);

                if (repoNode != null)
                {
                    changed |= MergeObjectsToMainTree(repoNode, testObjectNurse.Children);
                    changed |= NeighbourChecker(repoNode, testObjectNurse);
                    repoNode.TreeNode.Expand();
                    found = true;
                }



                if (!found)
                {
                    TestObjectNurse newTestNurse = new TestObjectNurse(testObjectNurse.TestObject);
                    TreeNode        node         = newTestNurse.TreeNode;
                    if (web)
                    {
                        newTestNurse.NodeName = testObjectNurse.TestObject.NodeName;

                        repoNurseNode.AddChild(newTestNurse);

                        changed = true;

                        TreeNodeHelper.FixTreeNodeImage(node, testObjectNurse.TestObject.ControlTypeString);

                        MergeObjectsToMainTree(newTestNurse, testObjectNurse.Children);
                        // NeighbourChecker(newTestNurse, testObjectNurse);

                        RaiseMergeCompleteEvent(true);
                        continue;
                    }
                    UIATestObject     uiaTestObject = (UIATestObject)testObjectNurse.TestObject;
                    AutomationElement addedElement  = uiaTestObject.AutomationElement;

                    string nodeName;

                    // if Element not exist, use the default condition, if exist, create new condition, because this can create index for object.
                    bool elementExist = (!addedElement.Current.BoundingRectangle.IsEmpty);
                    if (!elementExist)
                    {
                        string tempNewName;

                        if (!string.IsNullOrEmpty(uiaTestObject.ControlName))
                        {
                            tempNewName = uiaTestObject.ControlName;
                        }
                        else
                        {
                            tempNewName = uiaTestObject.ControlTypeString;
                        }

                        nodeName = SpyWindowHelper.DeriveControlName(repoNurseNode, tempNewName);
                    }
                    else
                    {
                        nodeName = SpyWindowHelper.DeriveControlName(repoNurseNode, addedElement);
                        //TODO should use the following logic
                        //newCondition = new UIACondition(fromNode, nodeName);
                    }

                    string nodeText = testObjectNurse.NodeName = nodeName;

                    //TestObjectNurse newTestNurse = new TestObjectNurse(uiaTestObject);

                    newTestNurse.NodeName = nodeText;

                    repoNurseNode.AddChild(newTestNurse);

                    // TreeNode node = newTestNurse.TreeNode;

                    changed = true;

                    TreeNodeHelper.FixTreeNodeImage(node, uiaTestObject.ControlTypeString);

                    MergeObjectsToMainTree(newTestNurse, testObjectNurse.Children);
                    NeighbourChecker(newTestNurse, testObjectNurse);

                    node.Expand();
                    RaiseMergeCompleteEvent(true);
                }
            }

            return(changed);
        }