public void GetWindowSearchConditionsWhenProcessIdIsValid()
 {
     List<AutomationSearchCondition> conditions = new AutomationSearchConditionFactory().GetWindowSearchConditions(1);
     Assert.AreEqual(2, conditions.Count);
     Assert.IsInstanceOfType(typeof (AndCondition), conditions[0].Condition);
     Assert.IsInstanceOfType(typeof (AndCondition), conditions[1].Condition);
 }
 public void GetWindowSearchConditionsWhenProcessIdIsInvalid()
 {
     List<AutomationSearchCondition> conditions = new AutomationSearchConditionFactory().GetWindowSearchConditions(0);
     Assert.AreEqual(2, conditions.Count);
     Assert.IsInstanceOf<PropertyCondition>(conditions[0].Condition);
     Assert.IsInstanceOf<PropertyCondition>(conditions[1].Condition);
 }
        public virtual AutomationElement FindWindow(string title, int processId)
        {
            List <AutomationSearchCondition> windowSearchConditions = new AutomationSearchConditionFactory().GetWindowSearchConditions(processId);

            foreach (var searchCondition in windowSearchConditions)
            {
                AutomationElement windowElement = Child(searchCondition.OfName(title));
                if (windowElement != null)
                {
                    return(windowElement);
                }
            }

            return(Child(0,
                         new[]
            {
                AutomationSearchCondition.GetWindowWithTitleBarSearchCondition(processId),
                AutomationSearchCondition.ByControlType(ControlType.TitleBar).OfName(title)
            }));
        }
        public virtual AutomationElement FindWindow(string title, int processId)
        {
            List<AutomationSearchCondition> windowSearchConditions = new AutomationSearchConditionFactory().GetWindowSearchConditions(processId);
            foreach (var searchCondition in windowSearchConditions)
            {
                AutomationElement windowElement = Child(searchCondition.OfName(title));
                if (windowElement != null) return windowElement;
            }

            return Child(0,
                         new[]
                             {
                                 AutomationSearchCondition.GetWindowWithTitleBarSearchCondition(processId),
                                 AutomationSearchCondition.ByControlType(ControlType.TitleBar).OfName(title)
                             });
        }