Ejemplo n.º 1
0
        public static AutomationElement TryWaitElement(this AutomationElement automationElement, TreeScope scope, Expression <Func <AutomationElement, bool> > condition, int?timeOut = null)
        {
            long start = PerfCounter.Ticks;

            var cond = ConditionBuilder.ToCondition(condition);

            var result = automationElement.FindFirst(scope, cond);

            if (result != null)
            {
                return(result);
            }

            while (true)
            {
                Thread.Sleep(DefaultSleep);

                result = automationElement.FindFirst(scope, cond);
                if (result != null)
                {
                    return(result);
                }

                if (((PerfCounter.Ticks - start) / PerfCounter.FrequencyMilliseconds) > (timeOut ?? DefaultTimeout))
                {
                    return(null);
                }
            }
        }
Ejemplo n.º 2
0
        public static AutomationElement Normalize(AutomationElement element)
        {
            if (element.Current.ControlType == ControlType.Window)
            {
                return(element);
            }

            TreeWalker walker = new TreeWalker(ConditionBuilder.ToCondition(a => a.Current.ControlType == ControlType.Window));

            return(walker.Normalize(element));
        }
Ejemplo n.º 3
0
        public static Condition ToCondition(Expression <Func <AutomationElement, bool> > condition)
        {
            Expression <Func <AutomationElement, bool> > clean = (Expression <Func <AutomationElement, bool> >)ExpressionCleaner.Clean(condition);

            ConditionBuilder builder = new ConditionBuilder {
                parameter = clean.Parameters.Single()
            };

            Expression expression = builder.Visit(clean.Body);

            return(AsCondition(expression));
        }
Ejemplo n.º 4
0
        public FilterOptionProxy LastFilter()
        {
            TreeWalker tw = new TreeWalker(ConditionBuilder.ToCondition(ae => ae.Current.ClassName == "FilterLine"));

            var filterLine = tw.GetLastChild(FilterBuilderControl);

            if (filterLine == null)
            {
                throw new ElementNotAvailableException("Last FilterLine not found");
            }

            return(new FilterOptionProxy(filterLine, this));
        }
Ejemplo n.º 5
0
        public void SetValueString(string value)
        {
            var valueControl = new TreeWalker(ConditionBuilder.ToCondition(a => a.Current.ControlType == ControlType.Custom)).GetLastChild(Element);

            switch (valueControl.Current.ClassName)
            {
            case "ValueLine":
                new ValueLineProxy(valueControl, null).StringValue = value;
                break;

            case "EntityLine":
                new EntityLineProxy(valueControl, null).Autocomplete(value);
                break;

            default: throw new InvalidOperationException();
            }
        }
Ejemplo n.º 6
0
        public static Condition ToCondition(Expression<Func<AutomationElement, bool>> condition)
        {
            Expression<Func<AutomationElement, bool>> clean = (Expression<Func<AutomationElement, bool>>)ExpressionCleaner.Clean(condition);

            ConditionBuilder builder = new ConditionBuilder { parameter = clean.Parameters.Single() };

            Expression expression = builder.Visit(clean.Body);

            return AsCondition(expression);
        }
Ejemplo n.º 7
0
        public static AutomationElement TryElement(this AutomationElement element, TreeScope scope, Expression <Func <AutomationElement, bool> > condition)
        {
            var c = ConditionBuilder.ToCondition(condition);

            return(element.TryElementByCondition(scope, c));
        }
Ejemplo n.º 8
0
        public static List <AutomationElement> Elements(this AutomationElement parent, TreeScope scope, Expression <Func <AutomationElement, bool> > condition)
        {
            var c = ConditionBuilder.ToCondition(condition);

            return(parent.FindAll(scope, c).Cast <AutomationElement>().ToList());
        }