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); }