VisualUIAVerify.Controls.AutomationElementTreeNode.FindOrInsertChildElement C# (CSharp) Method

FindOrInsertChildElement() private method

This method will insert currentTestTypeRootNode for automationElement between child nodes of this currentTestTypeRootNode. If there is existing currentTestTypeRootNode for the automationElement in children collection then return existing currentTestTypeRootNode.
private FindOrInsertChildElement ( AutomationElement automationElement ) : AutomationElementTreeNode
automationElement System.Windows.Automation.AutomationElement
return AutomationElementTreeNode
        internal AutomationElementTreeNode FindOrInsertChildElement(AutomationElement automationElement)
        {
            Debug.WriteLine("InsertChildElement ENTER");

            // this variable will hold the currentTestTypeRootNode for inserted automationElement
            AutomationElementTreeNode node = null;

            // if there is some currentTestTypeRootNode inserted before then try to find if it is not currentTestTypeRootNode for this automationElement
            if (this._newChildElementInserted || this._childrenStatus == ChildrenElementsStatus.Populated)
            {
                Debug.WriteLine("finding currentTestTypeRootNode for the element");
                try
                {
                    node = FindChildNodeForAutomationElementInternal(automationElement);
                }
                catch { /* it does not matter */ }
            }

            //if we didn't find child currentTestTypeRootNode for automationElement then create it
            if (node == null)
            {
                Debug.WriteLine("creating new currentTestTypeRootNode for the element");

                TreeNode newNode = CreateTreeNodeForAutomationElement(automationElement);

                this._newChildElementInserted = true;

                //add this new children to collection; we can call clear when there is no element inserted before

                //because this method does not have to be synchronized, we call AddChildrenNodesToTree directly
                //without using SyncManager
                if(this.AutomationElementTreeControl.InvokeRequired)
                {
                    this.AutomationElementTreeControl.Invoke(
                        new AddChildrenNodesToTreeNodeDelegate(AddChildrenNodesToTreeNodeInternal),
                        new TreeNode[] { newNode }, false, true);
                }
                else
                {
                    AddChildrenNodesToTreeNodeInternal(new TreeNode[] { newNode }, false, true);
                }

//                AddChildrenNodesToTreeNode(new TreeNode[] { newNode }, false, true);
                
                node = (AutomationElementTreeNode)newNode.Tag;
            }

            Debug.WriteLine("InsertChildElement EXIT");
            return node;
        }

Usage Example

コード例 #1
0
        /// <summary>
        /// this method will build currentTestTypeRootNode tree from rootNode to last item in path
        /// </summary>
        /// <returns>Returns last created AutomationElementTreeNode</returns>
        private AutomationElementTreeNode BuildNodeTreePath(AutomationElementTreeNode rootNode, Stack <AutomationElement> path)
        {
            // local variable to store current currentTestTypeRootNode
            AutomationElementTreeNode currentNode = rootNode;

            while (path.Count > 0 && currentNode != null)
            {
                AutomationElement elementOnPath = path.Pop();

                Debug.WriteLine("finding/inserting child currentTestTypeRootNode for automation element");
                currentNode = currentNode.FindOrInsertChildElement(elementOnPath);
                Debug.WriteLine("finding/inserting complete");
            }

            return(currentNode);
        }