public string Generate(AutomationElementTreeNode node) { try { return Generate(node, null); } catch (Exception e) { return e.ToString(); } }
public string Generate(AutomationElementTreeNode node, AutomationElementTreeNode parent) { var ret = ""; foreach (var child in node.Children) { _tabCount++; ret += Generate(child, node); _tabCount--; } var obj = new AutomationElementPropertyObject(node.AutomationElement); return CreateCode(obj, ret, parent); }
public string Generate(AutomationElementTreeNode node, AutomationElementTreeNode parent) { var ret = ""; foreach (var child in node.Children) { _tabCount++; ret += Generate(child, node); _tabCount--; } var obj = new AutomationElementPropertyObject(node.AutomationElement); if (obj == null) return string.Format("// Error Failed to create AutomationElementPropertyObject for object {0}", node.Text); return CreateCode(obj, ret, parent); }
/// <summary> /// This method will select last child currentTestTypeRootNode from the parameter currentTestTypeRootNode in a tree. If there is no child currentTestTypeRootNode then /// nothing happens. /// </summary> public void GoToLastChildFromNode(AutomationElementTreeNode node) { CheckNodeIsValid(node); if (node.Children.Count > 0) { TreeNode lastChildrenNode = node.Children[node.Children.Count - 1].TreeNode; _elementsTreeView.SelectedNode = lastChildrenNode; lastChildrenNode.EnsureVisible(); } //if no child currentTestTypeRootNode then nothing happens }
/// <summary> /// This method will select previous sibling currentTestTypeRootNode from the parameter currentTestTypeRootNode in a tree. If there is no previous sibling /// nothing happens. /// </summary> public void GoToPreviousSiblingFromNode(AutomationElementTreeNode node) { CheckNodeIsValid(node); TreeNode prevSiblingNode = node.TreeNode.PrevNode; if (prevSiblingNode != null) { this._elementsTreeView.SelectedNode = prevSiblingNode; prevSiblingNode.EnsureVisible(); } }
/// <summary> /// This method will select next sibling currentTestTypeRootNode from the parameter currentTestTypeRootNode in a tree. If there is no next sibling /// nothing happens. /// </summary> public void GoToNextSiblingFromNode(AutomationElementTreeNode node) { CheckNodeIsValid(node); TreeNode nextSiblingNode = node.TreeNode.NextNode; if (nextSiblingNode != null) { this._elementsTreeView.SelectedNode = nextSiblingNode; nextSiblingNode.EnsureVisible(); } }
// whatever mouse button pressed, it will select the currentTestTypeRootNode private void _elementsTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { //we will select the currentTestTypeRootNode which was clicked this._elementsTreeView.SelectedNode = e.Node; }
public AutomationElementTreeNodeSynchornizationManager(AutomationElementTreeNode OwnerNode) { this._ownerNode = OwnerNode; }
/// <summary> /// This method causes that the currentTestTypeRootNode in param becomes a root of a tree. /// </summary> public void ScopeToNode(AutomationElementTreeNode node) { CheckNodeIsValid(node); this._elementsTreeView.Nodes.Clear(); this._elementsTreeView.Nodes.Add(node.TreeNode); this._elementsTreeView.SelectedNode = node.TreeNode; }
/// <summary> /// This method will refresh currentTestTypeRootNode... /// </summary> public void RefreshNode(AutomationElementTreeNode Node) { CheckNodeIsValid(Node); Node.RefreshChildrenNodes(); PrepareNodeToExpand(Node); }
public LiveTreeNode(AutomationElementTreeNode node) { this._node = node; }
/// <summary> /// This method marks currentTestTypeRootNode in param as 'live' so it will listen to StructureChangedEvent and /// everytime the event fires the currentTestTypeRootNode will be refeshed. /// </summary> public void MarkElementLive(AutomationElementTreeNode node, bool live) { CheckNodeIsValid(node); node.Live = live; }
public string Generate(AutomationElementTreeNode node) { return Generate(node, null); }
/// <summary> /// This method is for validating that currentTestTypeRootNode in parametr is not null and belongs to this tree /// </summary> private void CheckNodeIsValid(AutomationElementTreeNode node) { if (node == null) throw new ArgumentNullException(); //does it belong to this tree? if ((node.AutomationElementTreeControl != this) || (node.TreeNode.TreeView != this._elementsTreeView)) throw new ArgumentException("This node does not belong to this tree control"); }
/// <summary> /// This method will make sure that for every child currentTestTypeRootNode of the currentTestTypeRootNode in parameter all children /// will be populated /// </summary> internal void PrepareNodeToExpand(AutomationElementTreeNode node) { foreach (AutomationElementTreeNode childNode in node.Children) { childNode.EnsureChildrenNodesPopulated(true); } }
/// <summary> /// this method will highlight newFocusedNode in the tree /// </summary> /// <param name="newFocusedNode"></param> private void HightlightNode(AutomationElementTreeNode newFocusedNode) { if (this._treeControl.InvokeRequired) { this._treeControl.BeginInvoke(new HightlightNodeDelegate(HightlightNode), newFocusedNode); } else { //there can be problem that the element does not longer exists try { this._treeControl.SelectedNode = newFocusedNode; newFocusedNode.TreeNode.EnsureVisible(); } catch (Exception) { } } }
/// <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; }
/// <summary> /// This method will select to parent AutomationElement from the currentTestTypeRootNode. If the parent element /// is not in a tree then this method will try to find the element and show him in a tree. /// </summary> public void GoToParentFromNode(AutomationElementTreeNode node) { CheckNodeIsValid(node); TreeNode nodeToSelect = node.TreeNode.Parent; if (nodeToSelect == null) { //there is no parent to this currentTestTypeRootNode, we should try to find one AutomationElement parentElement = this._treeWalker.GetParent(node.AutomationElement); if (parentElement == null) return; //we create tree currentTestTypeRootNode for the element TreeNode newRootNode = TreeHelper.CreateNodeForAutomationElement(parentElement, this); //take old root TreeNode currentRootNode = this._elementsTreeView.Nodes[0]; //clear the tree this._elementsTreeView.Nodes.Clear(); //insert it as a new root this._elementsTreeView.Nodes.Add(newRootNode); AutomationElementTreeNode newRootElementNode = (AutomationElementTreeNode)newRootNode.Tag; //insert old root to children collection of new root newRootElementNode.InsertChildNode(currentRootNode); nodeToSelect = newRootNode; } _elementsTreeView.SelectedNode = nodeToSelect; nodeToSelect.EnsureVisible(); //expand new root which cause populating of all child elements nodeToSelect.Expand(); }
/// <summary> /// This method will select first child currentTestTypeRootNode from the parameter currentTestTypeRootNode in a tree. If there is no child currentTestTypeRootNode then /// nothing happens. /// </summary> public void GoToFirstChildFromNode(AutomationElementTreeNode node) { CheckNodeIsValid(node); if (node.Children.Count > 0) { TreeNode firstChildrenNode = node.Children[0].TreeNode; _elementsTreeView.SelectedNode = firstChildrenNode; firstChildrenNode.EnsureVisible(); } //if there is no child currentTestTypeRootNode, then nothing }
private string CreateCode(AutomationElementPropertyObject obj, string inner, AutomationElementTreeNode parent) { _tabCount++; try { if (!String.IsNullOrEmpty(inner)) inner = String.Format("{0}{{{1}{2}{3}{4}}}", Tab, Environment.NewLine, inner, Environment.NewLine, Tab); var comment = String.Format("//UI Detection Details -- ControlType:{0}, Automation ID:{1}, Name:{2}, Framework:{3}", obj.ControlType, obj.AutomationId, obj.Name, obj.FrameworkType()); var generated = ""; AutomationElementPropertyObject parentObj = parent == null ? null : new AutomationElementPropertyObject(parent.AutomationElement); switch (obj.ControlType) { case "ControlType.Window": string fields = String.Join(string.Empty, _fields); inner = String.Format("{0}public class {1} : Screen{2}" + "{{{3}public {4}() : base(\"{5}\") {{ }}{6}{7}{8}{9}", Tab, obj.PropertyName(), Environment.NewLine + Tab, Environment.NewLine + Tab + _tab, obj.PropertyName(), obj.Name, Environment.NewLine + Tab + _tab, fields, inner.TrimStart('{', ' '), Environment.NewLine); break; case "ControlType.TitleBar": return inner.RemoveBrackets(); case "ControlType.MenuBar": inner = inner.RemoveBrackets(); _fields.Add(String.Format("{0}private {1} {2};{3}", Tab, obj.WhiteType(), obj.FieldName(), Environment.NewLine)); generated = obj.ApplyDefaultFormatByText(obj.WhiteType(), Tab); break; case "ControlType.MenuItem": _fields.Add(String.Format("{0}private {1} {2};{3}", Tab, obj.WhiteType(), obj.FieldName(), Environment.NewLine)); generated = String.Format( "{0}public {1} {2} {{ get {{ return {3} ?? ( {4} = {5}.MenuItem(\"{6}\")); }} }}{7}", Tab, obj.WhiteType(), obj.PropertyName(), obj.FieldName(), obj.FieldName(), parentObj.PropertyName(), obj.Name, Environment.NewLine); break; case "ControlType.Button": case "ControlType.Edit": case "ControlType.Text": _fields.Add(String.Format("{0}private {1} {2};{3}", Tab, obj.WhiteType(), obj.FieldName(), Environment.NewLine)); generated = obj.ApplyDefaultFormat(obj.WhiteType(), Tab); break; case "ControlType.Pane": inner = inner.RemoveBrackets(); //TODO: Scope searches to pane _fields.Add(String.Format("{0}private {1} {2};{3}", Tab, obj.WhiteType(), obj.FieldName(), Environment.NewLine)); generated = parentObj == null ? obj.ApplyDefaultFormat(obj.WhiteType(), Tab) : obj.ApplyDefaultFormatWithParent(Tab, parentObj); break; default: generated = String.Format("{0}// Control type '{1}' not supported{2}", Tab, obj.ControlType, Environment.NewLine); break; } return string.Format("{0}{1}{2}{3}{4}{5}{6}", Environment.NewLine, Tab, comment, Environment.NewLine, generated, inner, Environment.NewLine); } finally { _tabCount--; } }
private void SelectNode(AutomationElementTreeNode node) { if (node != null) { //there can be problem that the element does not longer exists try { this._treeControl.SelectedNode = node; node.TreeNode.EnsureVisible(); } catch (Exception) { } } }