internal List <IUiElement> GetAutomationElementsViaWildcards( GetControlCollectionCmdletBase cmdlet, bool caseSensitive, bool onlyOneResult, bool onlyTopLevel) { if (!cmdlet.CheckAndPrepareInput(cmdlet)) { return(null); } var resultCollection = new List <IUiElement>(); foreach (IUiElement inputObject in InputObject) { resultCollection = GetAutomationElementsWithWalker( inputObject, cmdlet.Name, cmdlet.AutomationId, cmdlet.Class, cmdlet.ControlType, caseSensitive, onlyOneResult, onlyTopLevel); } return(resultCollection); }
public static List<IUiElement> GetResultList_ViaWildcards_Legacy(IUiElement element, Condition condition, ControlSearcherData data) { var cmdletDerived = new GetControlCollectionCmdletBase(); List<IUiElement> resultList = cmdletDerived.GetAutomationElementsWithFindAll( element, data, condition, false, false, false, true); return resultList; }
internal static List<IUiElement> SearchByWildcardOrRegexViaUia( IUiElement inputObject, ControlSearcherData data, classic.Condition conditionsForWildCards, bool viaWildcardOrRegex) { var resultCollection = new List<IUiElement>(); if (null == inputObject) return resultCollection; try { var controlSearcherData = new ControlSearcherData { InputObject = data.InputObject ?? (new UiElement[]{ (UiElement)UiElement.RootElement }), Name = data.Name, AutomationId = data.AutomationId, Class = data.Class, Value = data.Value, ControlType = null != data.ControlType && 0 < data.ControlType.Length ? data.ControlType : (new string[] {}), CaseSensitive = caseSensitive }; var cmdlet1 = new GetControlCollectionCmdletBase(controlSearcherData); try { List<IUiElement> tempList = cmdlet1.GetAutomationElementsViaWildcards_FindAll( controlSearcherData, inputObject, conditionsForWildCards, cmdlet1.CaseSensitive, false, false, viaWildcardOrRegex); if (null == data.SearchCriteria || 0 == data.SearchCriteria.Length) { resultCollection.AddRange(tempList); } else { foreach (IUiElement tempElement2 in tempList.Where(elt => TestControlWithAllSearchCriteria(data.SearchCriteria, elt))) { resultCollection.Add(tempElement2); } } if (null != tempList) { tempList.Clear(); tempList = null; } return resultCollection; } catch (Exception eUnexpected) { (new GetControlCmdletBase()).WriteError( new GetControlCmdletBase(), "The input control or window has been possibly lost." + eUnexpected.Message, "UnexpectedError", ErrorCategory.ObjectNotFound, true); } cmdlet1 = null; return resultCollection; } catch (Exception eWildCardSearch) { (new GetControlCmdletBase()).WriteError( new GetControlCmdletBase(), "The input control or window has been possibly lost." + eWildCardSearch.Message, "UnexpectedError", ErrorCategory.ObjectNotFound, true); return resultCollection; } }
internal void SearchByWildcardViaUIA( //GetControlCmdletBase cmdlet, //T cmdlet, //CommonCmdletBase cmdlet, //HasTimeoutCmdletBase cmdlet, GetCmdletBase cmdlet, ref ArrayList resultCollection, AutomationElement inputObject, string name, string automationId, string className, string strValue, System.Windows.Automation.AndCondition conditionsForWildCards) { this.WriteVerbose((cmdlet as PSTestLib.PSCmdletBase), "[getting the control] using WildCard search"); try { // string cmdletValue = string.Empty; // try { // cmdletValue = cmdlet.Value; // } // catch {} // 20130220 GetControlCollectionCmdletBase cmdlet1 = new GetControlCollectionCmdletBase( //cmdlet.InputObject, null != cmdlet.InputObject ? cmdlet.InputObject : (new AutomationElement[]{ AutomationElement.RootElement }), //null, name, //cmdlet.Name, automationId, //cmdlet.AutomationId, className, //cmdlet.Class, //cmdlet.Value, //string.Empty != cmdlet.Value ? cmdlet.Value : null, strValue, (new string[] {}), this.caseSensitive); try { this.WriteVerbose((cmdlet as PSTestLib.PSCmdletBase), "using the GetAutomationElementsViaWildcards_FindAll method"); ArrayList tempList = cmdlet1.GetAutomationElementsViaWildcards_FindAll( cmdlet1, inputObject, conditionsForWildCards, cmdlet1.CaseSensitive, false, false); cmdlet.WriteVerbose( cmdlet, "there are " + tempList.Count.ToString() + " elements that match the conditions"); foreach (AutomationElement tempElement2 in tempList) { if (null == cmdlet.SearchCriteria || 0 == cmdlet.SearchCriteria.Length) { resultCollection.Add(tempElement2); cmdlet.WriteVerbose(cmdlet, "WildCardSearch: element added to the result collection (no SearchCriteria)"); } else { cmdlet.WriteVerbose(cmdlet, "WildCardSearch: checking search criteria"); if (testControlWithAllSearchCriteria(cmdlet, cmdlet.SearchCriteria, tempElement2)) { cmdlet.WriteVerbose(cmdlet, "WildCardSearch: the control matches the search criteria"); resultCollection.Add(tempElement2); cmdlet.WriteVerbose(cmdlet, "WildCardSearch: element added to the result collection (SearchCriteria)"); } // cmdlet.WriteVerbose(cmdlet, "WildCardSearch: element added to the result collection (SearchCriteria) (2)"); } // cmdlet.WriteVerbose(cmdlet, "WildCardSearch: element added to the result collection (SearchCriteria) (3)"); } cmdlet.WriteVerbose(cmdlet, "WildCardSearch: element(s) added to the result collection: " + resultCollection.Count.ToString()); } catch (Exception eUnexpected) { // this.WriteVerbose(this, eUnexpected.Message); this.WriteError( this, "The input control or window has been possibly lost." + eUnexpected.Message, "UnexpectedError", ErrorCategory.ObjectNotFound, true); } } catch (Exception eWildCardSearch) { this.WriteError( cmdlet, "The input control or window has been possibly lost." + eWildCardSearch.Message, "UnexpectedError", ErrorCategory.ObjectNotFound, true); } }
public AndCondition[] getControlsConditions(GetControlCollectionCmdletBase cmdlet) { System.Collections.Generic.List<AndCondition > conditions = new System.Collections.Generic.List<AndCondition > (); // 20130125 //if (cmdlet.ControlType != null && cmdlet.ControlType.Length > 0) { if (null != cmdlet.ControlType && 0 < cmdlet.ControlType.Length) { for (int i = 0; i < cmdlet.ControlType.Length; i++) { WriteVerbose(this, "control type: " + cmdlet.ControlType[i]); // 20130127 //conditions.Add(getControlConditions(((GetControlCmdletBase)cmdlet), cmdlet.ControlType[i])); // 20130128 //conditions.Add(getControlConditions(((GetControlCmdletBase)cmdlet), cmdlet.ControlType[i], cmdlet.CaseSensitive)); //conditions.Add(getControlConditions(((GetControlCmdletBase)cmdlet), cmdlet.ControlType[i], cmdlet.CaseSensitive, true)); conditions.Add(getControlConditions(((GetControlCmdletBase)cmdlet), cmdlet.ControlType[i], cmdlet.CaseSensitive, true) as AndCondition); } } else{ WriteVerbose(this, "without control type"); // 20130127 //conditions.Add(getControlConditions(((GetControlCmdletBase)cmdlet), "")); // 20130128 //conditions.Add(getControlConditions(((GetControlCmdletBase)cmdlet), "", cmdlet.CaseSensitive)); //conditions.Add(getControlConditions(((GetControlCmdletBase)cmdlet), "", cmdlet.CaseSensitive, true)); conditions.Add(getControlConditions(((GetControlCmdletBase)cmdlet), "", cmdlet.CaseSensitive, true) as AndCondition); } return conditions.ToArray(); }
internal ArrayList GetAutomationElementsViaWildcards_FindAll( GetControlCollectionCmdletBase cmdlet, AutomationElement inputObject, AndCondition conditions, bool caseSensitive, bool onlyOneResult, bool onlyTopLevel) { cmdlet.WriteVerbose(cmdlet, "in the GetAutomationElementsViaWildcards_FindAll method"); if (!cmdlet.CheckControl(cmdlet)) { return null; } cmdlet.WriteVerbose(cmdlet, "still in the GetAutomationElementsViaWildcards_FindAll method"); ArrayList resultCollection = new ArrayList(); resultCollection = getAutomationElementsWithFindAll( inputObject, cmdlet.Name, cmdlet.AutomationId, cmdlet.Class, cmdlet.Value, cmdlet.ControlType, conditions, caseSensitive, onlyOneResult, onlyTopLevel); cmdlet.WriteVerbose(cmdlet, "with some resultCollection"); if (null == resultCollection || resultCollection.Count == 0) { WriteVerbose( cmdlet, "getAutomationElementsWithWalker (" + inputObject.Current.Name + "," + cmdlet.Name + "," + cmdlet.AutomationId + "," + cmdlet.Class + "," + cmdlet.ControlType + "," + caseSensitive.ToString() + "," + onlyOneResult.ToString() + "," + onlyTopLevel.ToString() + ") returned null"); } return resultCollection; }
internal ArrayList GetAutomationElementsViaWildcards( GetControlCollectionCmdletBase cmdlet, bool caseSensitive, bool onlyOneResult, bool onlyTopLevel) { if (!cmdlet.CheckControl(cmdlet)) { return null; } ArrayList resultCollection = new ArrayList(); foreach (AutomationElement inputObject in this.InputObject) { resultCollection = getAutomationElementsWithWalker( inputObject, cmdlet.Name, cmdlet.AutomationId, cmdlet.Class, cmdlet.ControlType, caseSensitive, onlyOneResult, onlyTopLevel); if (null == resultCollection) { WriteVerbose( cmdlet, "getAutomationElementsWithWalker (" + inputObject.Current.Name + "," + cmdlet.Name + "," + cmdlet.AutomationId + "," + cmdlet.Class + "," + cmdlet.ControlType + "," + caseSensitive.ToString() + "," + onlyOneResult.ToString() + "," + onlyTopLevel.ToString() + ") returrned null"); } } return resultCollection; }
internal List<IUiElement> GetAutomationElementsViaWildcards( GetControlCollectionCmdletBase cmdlet, bool caseSensitive, bool onlyOneResult, bool onlyTopLevel) { if (!cmdlet.CheckAndPrepareInput(cmdlet)) { return null; } var resultCollection = new List<IUiElement>(); foreach (IUiElement inputObject in InputObject) { resultCollection = GetAutomationElementsWithWalker( inputObject, cmdlet.Name, cmdlet.AutomationId, cmdlet.Class, cmdlet.ControlType, caseSensitive, onlyOneResult, onlyTopLevel); } return resultCollection; }
internal static List <IUiElement> SearchByWildcardOrRegexViaUia( IUiElement inputObject, ControlSearcherData data, classic.Condition conditionsForWildCards, bool viaWildcardOrRegex) { var resultCollection = new List <IUiElement>(); if (null == inputObject) { return(resultCollection); } try { var controlSearcherData = new ControlSearcherData { InputObject = data.InputObject ?? (new UiElement[] { (UiElement)UiElement.RootElement }), Name = data.Name, AutomationId = data.AutomationId, Class = data.Class, Value = data.Value, ControlType = null != data.ControlType && 0 < data.ControlType.Length ? data.ControlType : (new string[] {}), CaseSensitive = caseSensitive }; var cmdlet1 = new GetControlCollectionCmdletBase(controlSearcherData); try { List <IUiElement> tempList = cmdlet1.GetAutomationElementsViaWildcards_FindAll( controlSearcherData, inputObject, conditionsForWildCards, cmdlet1.CaseSensitive, false, false, viaWildcardOrRegex); if (null == data.SearchCriteria || 0 == data.SearchCriteria.Length) { resultCollection.AddRange(tempList); } else { foreach (IUiElement tempElement2 in tempList.Where(elt => TestControlWithAllSearchCriteria(data.SearchCriteria, elt))) { resultCollection.Add(tempElement2); } } if (null != tempList) { tempList.Clear(); tempList = null; } return(resultCollection); } catch (Exception eUnexpected) { (new GetControlCmdletBase()).WriteError( new GetControlCmdletBase(), "The input control or window has been possibly lost." + eUnexpected.Message, "UnexpectedError", ErrorCategory.ObjectNotFound, true); } cmdlet1 = null; return(resultCollection); } catch (Exception eWildCardSearch) { (new GetControlCmdletBase()).WriteError( new GetControlCmdletBase(), "The input control or window has been possibly lost." + eWildCardSearch.Message, "UnexpectedError", ErrorCategory.ObjectNotFound, true); return(resultCollection); } }