Пример #1
0
        /// <summary>
        ///     Find a UIItem (of a particular type) based on SearchCriteria
        /// </summary>
        /// <param name="searchCriteria">UIItem identification conditions</param>
        /// <param name="scope">Scope of search</param>
        /// <param name="timeout">Timeout value for search (milliseconds)</param>
        /// <returns>Matching UIItem</returns>
        protected static T FindUIItem(
            SearchCriteria searchCriteria,
            UIItem scope,
            int timeout)
        {
            if (timeout > 0)
            {
                WhiteConfigHelper.OriginalFindUIItemTimeout = timeout;
            }

            if (scope == null)
            {
                scope = WorkSpace.MainWindow.Window;
            }

            Report.Output(
                Report.Level.Debug,
                Resources.UIItemFindUsingSearchCriteriaMsg,
                searchCriteria.ToString(),
                typeof(T).ToString(),
                scope.PrimaryIdentification);

            T   matchingUIItem = null;
            var stopwatch      = new Stopwatch();
            var elapsedTime    = new TimeSpan();

            try
            {
                stopwatch.Start();
                matchingUIItem = scope.Get <T>(searchCriteria);
                elapsedTime    = stopwatch.Elapsed;

                Report.Output(
                    Report.Level.Debug,
                    Resources.UIItemFoundMsg,
                    elapsedTime);
            }
            catch (AutomationException ex)
            {
                elapsedTime = stopwatch.Elapsed;

                Report.Output(
                    Report.Level.Debug,
                    Resources.UIItemNotFoundMsg,
                    elapsedTime,
                    ex.Message);
            }
            finally
            {
                stopwatch.Stop();

                if (timeout > 0)
                {
                    WhiteConfigHelper.ResetFindUIItemTimeout();
                }
            }

            return(matchingUIItem);
        }
Пример #2
0
        public static T Find(SearchCriteria searchCriteria, UIItem item)
        {
            T element = null;

            try
            {
                element = item.Get <T>(searchCriteria);
            }
            catch (AutomationException ex)
            {
                LoggerUtil.Info($"Element is not found: {ex}");
            }

            return(element);
        }
Пример #3
0
        /// <summary>
        ///     Find a UIItem (of a particular type) based on SearchCriteria and ExtraCriteria
        /// </summary>
        /// <param name="searchCriteria">UIItem identification conditions</param>
        /// <param name="automationProperty">AutomationElement property</param>
        /// <param name="automationPropertyValue">Value of AutomationElement property</param>
        /// <param name="scope">Scope of search</param>
        /// <param name="timeout">Timeout value for search (milliseconds)</param>
        /// <returns>Matching UIItem</returns>
        protected static T FindUIItem(
            SearchCriteria searchCriteria,
            AutomationProperty automationProperty,
            object automationPropertyValue,
            UIItem scope,
            int timeout)
        {
            if (timeout > 0)
            {
                WhiteConfigHelper.OriginalFindUIItemTimeout = timeout;
            }

            if (scope == null)
            {
                scope = WorkSpace.MainWindow.Window;
            }

            Report.Output(
                Report.Level.Debug,
                Resources.UIItemFindUsingExtraCriteriaMsg,
                searchCriteria.ToString(),
                typeof(T).ToString(),
                automationProperty.ProgrammaticName,
                automationPropertyValue,
                scope.PrimaryIdentification);

            T   matchingUIItem = null;
            var hasFound       = true;
            var stopwatch      = new Stopwatch();
            var elapsedTime    = new TimeSpan();

            try
            {
                var index = 0;
                stopwatch.Start();

                do
                {
                    matchingUIItem = scope.Get <T>(searchCriteria.AndIndex(index));
                    index++;

                    Report.Output(
                        Report.Level.Debug,
                        Resources.UIItemCheckUsingExtraCriteriaMsg,
                        matchingUIItem.PrimaryIdentification,
                        matchingUIItem.Name);
                } while (!matchingUIItem.ValueOfEquals(automationProperty, automationPropertyValue));
            }
            catch (AutomationException ex)
            {
                elapsedTime = stopwatch.Elapsed;

                Report.Output(
                    Report.Level.Debug,
                    Resources.UIItemNotFoundMsg,
                    elapsedTime,
                    ex.Message);

                hasFound       = false;
                matchingUIItem = null;
            }
            finally
            {
                if (hasFound)
                {
                    elapsedTime = stopwatch.Elapsed;
                    Report.Output(
                        Report.Level.Debug,
                        Resources.UIItemFoundMsg,
                        elapsedTime);
                }

                stopwatch.Stop();

                if (timeout > 0)
                {
                    WhiteConfigHelper.ResetFindUIItemTimeout();
                }
            }

            return(matchingUIItem);
        }
Пример #4
0
 public void Close()
 {
     settingsControl.Get <Button>(SearchCriteria.ByAutomationId("CloseSettings")).Click();
     Thread.Sleep(300); // Wait 0.3 seconds for animation to finish
 }