/// <summary> /// Gets the control. /// </summary> /// <typeparam name="TControl">The control type.</typeparam> /// <param name="pattern">The search pattern to locate the control.</param> /// <param name="predicate">Additional control predicate in case the search pattern yields multiple matches.</param> /// <param name="depth">The maximum search depth.</param> /// <returns>The control object.</returns> public virtual TControl Find <TControl>(ISearchPattern pattern = null, Predicate <IControl> predicate = null, int?depth = null) where TControl : IControlObject { var result = (TControl)Activator.CreateInstance(((IRootObjectInternal)RootInternal).UIObjectInterfaceResolver.Resolve <TControl>()); (result as IUIObjectInternal).Init(this); (result as IControlObjectInternal).Init(pattern, predicate); (result as IUIObjectInternal).Init(depth ?? ControlSearchDepth, null); return(result); }
/// <summary> /// Add another search constraint. /// </summary> /// <param name="additionalSearch">Additional search constraint.</param> /// <returns>The conjunction.</returns> public Search <TControlPattern> And(ISearchPattern additionalSearch) { if (additionalSearch != null) { foreach (var p in additionalSearch.GetPatternItems()) { And(p.Key, p.Value); } } return(this); }
/// <summary> /// Gets all matching controls. /// </summary> /// <typeparam name="TControl">The control type.</typeparam> /// <param name="pattern">The search pattern to locate the control.</param> /// <param name="predicate">Additional control predicate in case the search pattern yields multiple matches.</param> /// <param name="depth">The maximum search depth.</param> /// <returns>The control enumeration.</returns> public virtual IEnumerable <TControl> FindAll <TControl>(ISearchPattern pattern = null, Predicate <IControl> predicate = null, int?depth = null) where TControl : IControlObject { int next = 0; while (true) { TControl result = Find <TControl>(pattern, predicate); (result as IUIObjectInternal).Init(depth, null); (result as IUIObjectInternal).Index = next++; if (!result.Exists) { break; } yield return(result); } }
/// <inheritdoc/> public override void Init(ISearchPattern pattern, Predicate <IControl> predicate) { ControlPattern conjunction = new ControlPattern(); if (pattern != null) { foreach (var p in pattern.GetPatternItems()) { conjunction.Add(p.Key, p.Value); } } foreach (var p in SearchPattern.GetPatternItems()) { if (!conjunction.GetPatternItems().Any(e => e.Key == p.Key)) { conjunction.Add(p.Key, p.Value); } } base.Init(conjunction, predicate); }
/// <summary> /// Finds all nodes with the given full class name. /// </summary> /// <param name="source">The node to search from.</param> /// <param name="pattern">The search pattern.</param> /// <param name="depth">The search depth.</param> /// <returns>The enumeration nodes.</returns> /// <typeparam name="T">The expected object type.</typeparam> internal static IReadOnlyList <T> MyFindAll <T>(this IObjectTreeNode source, ISearchPattern pattern, int depth = 1) where T : class, IObjectTreeNode { List <T> result = new List <T>(); Queue <Tuple <IObjectTreeNode, int> > q = new Queue <Tuple <IObjectTreeNode, int> >(); q.Enqueue(new Tuple <IObjectTreeNode, int>(source, 0)); while (q.Count > 0) { Tuple <IObjectTreeNode, int> current = q.Dequeue(); if (current == null) { continue; } if (current.Item2 != 0) { object value; if (pattern.GetPatternItems().All((i) => current.Item1.TryGetProperty(i.Key, out value) && i.Value.Equals(value))) { result.Add(current.Item1.Cast <T>()); continue; // do not further search on this path } } if (current.Item2 != depth) { foreach (IObjectTreeNode child in current.Item1.Children) { q.Enqueue(new Tuple <IObjectTreeNode, int>(child, current.Item2 + 1)); } } } return(result); }
/// <summary> /// Create search pattern from the given pattern. /// </summary> /// <param name="pattern">The pattern.</param> /// <returns>The search.</returns> public static Search By(ISearchPattern pattern) { return(Any.And(pattern) as Search); }
/// <summary> /// Initializes the page object. /// </summary> /// <param name="searchPattern">The search pattern.</param> public void Init(ISearchPattern searchPattern) { this.searchPattern = searchPattern; }
/// <summary> /// Initialize the control object. /// </summary> /// <param name="pattern">The search pattern used to locate the control.</param> /// <param name="predicate">Additional control predicate in case the search pattern yields multiple matches.</param> public virtual void Init(ISearchPattern pattern, Predicate <IControl> predicate = null) { this.pattern = pattern; this.predicate = predicate; }
/// <summary> /// Find all controls from the page object root node. /// </summary> /// <typeparam name="TControl">The type of the control.</typeparam> /// <param name="pattern">The search pattern.</param> /// <param name="depth">The search depth (null for default).</param> /// <returns>The controls.</returns> public IReadOnlyList <TControl> FindAll <TControl>(ISearchPattern pattern, int depth) where TControl : class, IObjectTreeNode { return(Root.MyFindAll <TControl>(pattern, depth)); }
/// <summary> /// Find all controls from the page object root node. /// </summary> /// <typeparam name="TControl">The type of the control.</typeparam> /// <param name="pattern">The search pattern.</param> /// <returns>The controls.</returns> public IReadOnlyList <TControl> FindAll <TControl>(ISearchPattern pattern) where TControl : class, IObjectTreeNode { return(FindAll <TControl>(pattern, ControlSearchDepth)); }
/// <summary> /// Find a control from the page object root node. /// </summary> /// <typeparam name="TControl">The type of the control.</typeparam> /// <param name="pattern">The search pattern.</param> /// <param name="result">The control or null.</param> /// <param name="depth">The search depth.</param> /// <returns>Whether the control was found.</returns> public bool TryFind <TControl>(ISearchPattern pattern, out TControl result, int depth) where TControl : class, IObjectTreeNode { return(Root.TryFind(pattern, depth, 0, out result)); }
/// <summary> /// Find a control from the page object root node. /// </summary> /// <typeparam name="TControl">The type of the control.</typeparam> /// <param name="pattern">The search pattern.</param> /// <param name="result">The control or null.</param> /// <returns>Whether the control was found.</returns> public bool TryFind <TControl>(ISearchPattern pattern, out TControl result) where TControl : class, IObjectTreeNode { return(TryFind(pattern, out result, ControlSearchDepth)); }
/// <summary> /// Find a control from the page object root node. /// </summary> /// <typeparam name="TControl">The type of the control.</typeparam> /// <param name="pattern">The search pattern.</param> /// <param name="depth">The search depth.</param> /// <returns>The control or null.</returns> public TControl Find <TControl>(ISearchPattern pattern, int depth) where TControl : class, IObjectTreeNode { return(Root.Find <TControl>(pattern, depth)); }
/// <summary> /// Find a control from the page object root node. /// </summary> /// <typeparam name="TControl">The type of the control.</typeparam> /// <param name="pattern">The search pattern.</param> /// <returns>The control or null if fails.</returns> public TControl Find <TControl>(ISearchPattern pattern) where TControl : class, IObjectTreeNode { return(Find <TControl>(pattern, ControlSearchDepth)); }
/// <summary> /// Initialize the control object. /// </summary> /// <param name="pattern">The search pattern used to locate the control.</param> /// <param name="predicate">Additional control predicate in case the search pattern yields multiple matches.</param> public virtual void Init(ISearchPattern pattern, Predicate <IControl> predicate) { Node.Init(pattern, predicate); }