public String[] GetObjectList(String windowName) { if (String.IsNullOrEmpty(windowName)) { throw new XmlRpcFaultException(123, "Argument cannot be empty."); } string matchedKey = null; Hashtable objectHT = new Hashtable(); ArrayList objectList = new ArrayList(); AutomationElement windowHandle = utils.GetWindowHandle(windowName); if (windowHandle == null) { throw new XmlRpcFaultException(123, "Unable to find window: " + windowName); } InternalTreeWalker walker = new InternalTreeWalker(); utils.InternalGetObjectList(walker.walker.GetFirstChild(windowHandle), ref objectList, ref objectHT, ref matchedKey, true, null, windowHandle.Current.Name); if (utils.debug || utils.writeToFile != null) { LogMessage(objectList.Count); foreach (string key in objectHT.Keys) { LogMessage("Key: " + ((Hashtable)objectHT[key])["key"]); LogMessage("Parent: " + ((Hashtable)objectHT[key])["parent"]); LogMessage("Obj index: " + ((Hashtable)objectHT[key])["obj_index"]); LogMessage("Class: " + ((Hashtable)objectHT[key])["class"]); foreach (string child in (ArrayList)((Hashtable)objectHT[key])["children"]) { LogMessage("Children: " + child); } } } walker = null; objectHT = null; windowHandle = null; try { return(objectList.ToArray(typeof(string)) as string[]); } finally { objectList = null; } }
private int HandleSubMenu(AutomationElement childHandle, AutomationElement firstObjHandle, ref ArrayList menuList) { string matchedKey = null; Hashtable objectHT = new Hashtable(); try { menuList.Clear(); utils.InternalGetObjectList(childHandle, ref menuList, ref objectHT, ref matchedKey); if (menuList.Count > 0) { // Set it back to old state, // else the menu selection left there utils.InternalClick(firstObjHandle); // Don't process the last item return(1); } else { LogMessage("menuList.Count <= 0: " + menuList.Count); } } catch (Exception ex) { LogMessage(ex); } finally { objectHT = null; } return(0); }
private int InternalComboHandler(String windowName, String objName, String item, ref String selectedItem, String actionType = "Select", ArrayList childList = null) { bool verify = actionType == "Verify" ? true : false; ControlType[] comboTtype = new ControlType[3] { ControlType.ComboBox, ControlType.ListItem, ControlType.List/*, ControlType.Text */ }; AutomationElement childHandle = utils.GetObjectHandle(windowName, objName, comboTtype, !verify); Object pattern = null; Object invokePattern = null; AutomationElement elementItem = null; ControlType[] type = new ControlType[1] { ControlType.Button }; try { LogMessage("Handle name: " + childHandle.Current.Name + " - " + childHandle.Current.ControlType.ProgrammaticName); if (!utils.IsEnabled(childHandle, !verify)) { throw new XmlRpcFaultException(123, "Object state is disabled"); } elementItem = null; /* * elementItem = utils.GetObjectHandle(childHandle, "Open", type, true); * if (elementItem != null) * { * LogMessage("elementItem: " + elementItem.Current.Name + * " - " + elementItem.Current.ControlType.ProgrammaticName); * } */ if (childHandle.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out pattern) || childHandle.TryGetCurrentPattern( InvokePattern.Pattern, out invokePattern) || (elementItem != null && elementItem.TryGetCurrentPattern( InvokePattern.Pattern, out invokePattern))) { LogMessage("ExpandCollapsePattern"); // Retry max 5 times for (int i = 0; i < 5; i++) { switch (actionType) { case "Hide": if (invokePattern != null) { ((InvokePattern)invokePattern).Invoke(); return(1); } else if (pattern != null) { ((ExpandCollapsePattern)pattern).Collapse(); // Required to wait 1 second, // before checking the state and retry collapsing utils.InternalWait(1); if (((ExpandCollapsePattern)pattern).Current.ExpandCollapseState == ExpandCollapseState.Collapsed) { // Hiding same combobox multiple time consecutively // fails. Check for the state and retry to collapse LogMessage("Collapsed"); return(1); } } break; case "Show": case "Select": case "Verify": // elementItem = utils.GetObjectHandle(childHandle, "Open", // type, !verify); elementItem = null; if (invokePattern != null || (elementItem != null && elementItem.TryGetCurrentPattern(InvokePattern.Pattern, out invokePattern))) { ((InvokePattern)invokePattern).Invoke(); } else if (pattern != null) { ((ExpandCollapsePattern)pattern).Expand(); } // Required to wait 1 second, // before checking the state and retry expanding utils.InternalWait(1); if (invokePattern != null || (pattern != null && ((ExpandCollapsePattern)pattern).Current.ExpandCollapseState == ExpandCollapseState.Expanded)) { // Selecting same combobox multiple time consecutively // fails. Check for the state and retry to expand LogMessage("Expaneded"); if (actionType == "Show") { return(1); } else { return(SelectListItem(childHandle, item, verify) ? 1 : 0); } } break; case "GetComboValue": Object selectionPattern = null; LogMessage("GetComboValue"); // elementItem = utils.GetObjectHandle(childHandle, "Open", // type, true); elementItem = null; if (invokePattern != null || (elementItem != null && elementItem.TryGetCurrentPattern(InvokePattern.Pattern, out invokePattern))) { LogMessage("InvokePattern"); childHandle.SetFocus(); utils.InternalClick(elementItem); // InvokePattern doesn't work with Virtual Network // Editor of VMware Workstation, so used the above InternalClick //((InvokePattern)invokePattern).Invoke(); } else if (pattern != null) { LogMessage("ExpandCollapsePattern"); ((ExpandCollapsePattern)pattern).Expand(); } Object valuePattern; if (childHandle.TryGetCurrentPattern(ValuePattern.Pattern, out valuePattern)) { selectedItem = ((ValuePattern)valuePattern).Current.Value; return(1); } // Required to wait 1 second, // before checking the state and retry expanding utils.InternalWait(1); LogMessage("Handle name: " + childHandle.Current.Name + " - " + childHandle.Current.ControlType.ProgrammaticName); bool typeExist = utils.InternalWaitTillChildControlTypeExist(childHandle, type); LogMessage("Control type exist: " + typeExist); AutomationElementCollection c = childHandle.FindAll(TreeScope.Subtree, Condition.TrueCondition); LogMessage("AutomationElementCollection " + c.Count); foreach (AutomationElement e in c) { LogMessage(e.Current.Name + " : " + e.Current.ControlType.ProgrammaticName); bool status = false; if (e.TryGetCurrentPattern(SelectionItemPattern.Pattern, out selectionPattern)) { status = ((SelectionItemPattern)selectionPattern).Current.IsSelected; if (status) { LogMessage("Selected: " + e.Current.Name); selectedItem = e.Current.Name; ((ExpandCollapsePattern)pattern).Collapse(); return(1); } } } LogMessage("Unable to find selected combo box value"); c = null; selectionPattern = null; if (invokePattern != null) { ((InvokePattern)invokePattern).Invoke(); } else if (pattern != null) { ((ExpandCollapsePattern)pattern).Collapse(); } return(0); case "GetAllItem": string matchedKey = null; Hashtable objectHT = new Hashtable(); ArrayList tmpChildList = new ArrayList(); InternalTreeWalker w = new InternalTreeWalker(); elementItem = utils.GetObjectHandle(childHandle, "Open", type, true); // Changes based on QT 5.0.2 if (invokePattern != null || (elementItem != null && elementItem.TryGetCurrentPattern(InvokePattern.Pattern, out invokePattern))) { ((InvokePattern)invokePattern).Invoke(); } else if (pattern != null) { ((ExpandCollapsePattern)pattern).Expand(); } // Required to wait 1 second, // before checking the state and retry expanding utils.InternalWait(1); utils.InternalGetObjectList( w.walker.GetFirstChild(childHandle), ref tmpChildList, ref objectHT, ref matchedKey, true, null, null, ControlType.ListItem); if (invokePattern != null) { ((InvokePattern)invokePattern).Invoke(); } else if (pattern != null) { ((ExpandCollapsePattern)pattern).Collapse(); } // For Linux compatibility Hashtable propertyHT; foreach (String key in objectHT.Keys) { propertyHT = (Hashtable)objectHT[key]; string className = (string)propertyHT["class"]; if (className != null && className.Contains("list_item")) { // Add only list items childList.Add(propertyHT["label"]); } } w = null; tmpChildList = null; propertyHT = objectHT = null; if (childList.Count > 0) { // Don't process the last item return(1); } else { LogMessage("childList.Count <= 0: " + childList.Count); } return(0); } } } // Handle selectitem and verifyselect on list. // Get ExpandCollapsePattern fails on list, // VM Library items are selected and // verified correctly on Player with this fix else { LogMessage("SelectListItem"); childHandle.SetFocus(); return(SelectListItem(childHandle, item, verify) ? 1 : 0); } } catch (Exception ex) { LogMessage(ex); if (ex is XmlRpcFaultException) { throw; } else { throw new XmlRpcFaultException(123, "Unhandled exception: " + ex.Message); } } finally { comboTtype = type = null; pattern = invokePattern = null; elementItem = childHandle = null; } return(0); }
private int InternalComboHandler(String windowName, String objName, String item, String actionType = "Select", ArrayList childList = null) { AutomationElement childHandle = GetObjectHandle(windowName, objName); Object pattern = null; try { LogMessage("Handle name: " + childHandle.Current.Name + " - " + childHandle.Current.ControlType.ProgrammaticName); if (!utils.IsEnabled(childHandle)) { throw new XmlRpcFaultException(123, "Object state is disabled"); } if (childHandle.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out pattern)) { LogMessage("ExpandCollapsePattern"); // Retry max 5 times for (int i = 0; i < 5; i++) { switch (actionType) { case "Hide": ((ExpandCollapsePattern)pattern).Collapse(); // Required to wait 1 second, // before checking the state and retry collapsing utils.InternalWait(1); if (((ExpandCollapsePattern)pattern).Current.ExpandCollapseState == ExpandCollapseState.Collapsed) { // Hiding same combobox multiple time consecutively // fails. Check for the state and retry to collapse LogMessage("Collapsed"); return(1); } break; case "Show": case "Select": case "Verify": ((ExpandCollapsePattern)pattern).Expand(); // Required to wait 1 second, // before checking the state and retry expanding utils.InternalWait(1); if (((ExpandCollapsePattern)pattern).Current.ExpandCollapseState == ExpandCollapseState.Expanded) { // Selecting same combobox multiple time consecutively // fails. Check for the state and retry to expand LogMessage("Expaneded"); if (actionType == "Show") { return(1); } else { childHandle.SetFocus(); bool verify = actionType == "Verify" ? true : false; return(SelectListItem(childHandle, item, verify) ? 1 : 0); } } break; case "GetAllItem": string matchedKey = null; Hashtable objectHT = new Hashtable(); ArrayList tmpChildList = new ArrayList(); InternalTreeWalker w = new InternalTreeWalker(); utils.InternalGetObjectList( w.walker.GetFirstChild(childHandle), ref tmpChildList, ref objectHT, ref matchedKey, true, null, null, ControlType.ListItem); // For Linux compatibility Hashtable propertyHT; foreach (String key in objectHT.Keys) { propertyHT = (Hashtable)objectHT[key]; string className = (string)propertyHT["class"]; if (className != null && className.Contains("list_item")) { // Add only list items childList.Add(propertyHT["label"]); } } w = null; tmpChildList = null; propertyHT = objectHT = null; if (childList.Count > 0) { // Don't process the last item return(1); } else { LogMessage("childList.Count <= 0: " + childList.Count); } return(0); } } } // Handle selectitem and verifyselect on list. // Get ExpandCollapsePattern fails on list, // VM Library items are selected and // verified correctly on Player with this fix else { childHandle.SetFocus(); bool verify = actionType == "Verify" ? true : false; return(SelectListItem(childHandle, item, verify) ? 1 : 0); } } catch (Exception ex) { LogMessage(ex); if (ex is XmlRpcFaultException) { throw; } else { throw new XmlRpcFaultException(123, "Unhandled exception: " + ex.Message); } } finally { pattern = null; childHandle = null; } return(0); }