.net - Select treeview item with item path using C# - Used in Coded UI Testing -
i need select items in treeview in coded ui test automation. came own solution. see performance issues running slow. suggestions on improving performance?
this 1 wrote extension method way can use inline treeview control.
also, node path custom assumption ">" not used in item text. have given example of node text in summary
/// <summary> /// selects item in tree view control. /// eg nodepath: 2017>jan>21. expand 2017 jan , select 21st date in treeview /// </summary> /// <param name="parentcontrol">tree view control</param> /// <param name="nodepath">path item selected located. parent , child separated '>'</param> public static void selectitemintreeview(this wpftree parentcontrol, string nodepath) { char splitter = '>'; string[] treepath = nodepath.split(splitter); wpftreeitem parentnode = null; uitestcontrolcollection childnodes = parentcontrol.nodes; bool itemselected = false; string root = treepath[0]; string lastitemintreepath = treepath[treepath.length - 1]; foreach (string pathelement in treepath) { bool found = false; foreach (wpftreeitem item in childnodes) { uitestcontrol itemcheck = item.getchildren().where(x => x.controltype == controltype.text && x.name == pathelement).firstordefault(); if (itemcheck != null) { found = true; wpftreeitem currentitem = null; if (itemcheck.name.equals(lastitemintreepath)) { item.selected = true; itemselected = true; } else { currentitem = (parentnode == null) ? new wpftreeitem(parentcontrol) : new wpftreeitem(parentnode); currentitem.technologyname = "uia"; currentitem.searchproperties[wpftreeitem.propertynames.name] = item.name; currentitem.searchconfigurations.add(searchconfiguration.expandwhilesearching); currentitem.expanded = true; parentnode = currentitem; } break; } } if (!found) { assert.fail("error in tree view path. correct input treeview path: {0}", nodepath); } else { if (!itemselected) { childnodes = parentnode.nodes; } } } }
Comments
Post a Comment