示例#1
0
 public override void Apply(SearchCriteria searchCriteria)
 {
     searchCriteria.AndIndex(index);
 }
示例#2
0
文件: QAItem.cs 项目: EXHALE97/GIT-VS
        /// <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);
        }
示例#3
0
        /* Class internal helper methods */
        private SearchCriteria GetBy(String id)
        {
            System.Threading.Thread.Sleep(waitAfterAction);
            SearchCriteria sCrit = null;
            String         by    = "";
            int            x     = id.IndexOf(SEPARATOR);

            if (x > 0 && locators.Contains(id.Substring(0, x)))
            {
                by = id.Substring(0, x);
                id = id.Substring(x + 1);
            }
            if (by.Equals("automationId"))
            {
                sCrit = SearchCriteria.ByAutomationId(id);
            }
            else if (by.Equals("className"))
            {
                sCrit = SearchCriteria.ByClassName(id);
            }
            else if (by.Equals("controlType"))
            {
                sCrit = SearchCriteria.ByControlType(GetControlTypes(id));
            }
            else if (by.Equals("text"))
            {
                sCrit = SearchCriteria.ByText(id);
            }
            else if (by.Equals("xpath"))
            {
                int    startIndex = 2; int indexx = 0;
                String element = id.Substring(startIndex, (id.IndexOf('[') - startIndex)).Trim();
                sCrit = SearchCriteria.ByControlType(GetControlTypes(element));
                while ((startIndex = id.IndexOf("[@")) >= 0)
                {
                    id         = id.Substring(startIndex + 2);
                    startIndex = id.IndexOf("='");
                    String attribute = id.Substring(0, startIndex).Trim();
                    String param     = id.Substring(startIndex + 2, (id.IndexOf("']") - (startIndex + 2)));
                    if (attribute.Equals("automationId"))
                    {
                        sCrit = sCrit.AndAutomationId(param);
                    }
                    else if (attribute.Equals("className"))
                    {
                        sCrit = sCrit.AndByClassName(param);
                    }
                    else if (attribute.Equals("text"))
                    {
                        sCrit = sCrit.AndByText(param);
                    }
                }

                if ((startIndex = id.IndexOf('[')) >= 0)
                {
                    indexx = Convert.ToInt16(id.Substring(startIndex + 1, id.LastIndexOf(']') - (startIndex + 1)).Trim());
                }

                if (indexx > 0)
                {
                    sCrit = sCrit.AndIndex(indexx - 1);
                }
            }
            else
            {
                sCrit = SearchCriteria.ByText(id);
            }

            return(sCrit);
        }
示例#4
0
        /// <summary>
        /// given a criteria, find a control within a window
        /// </summary>
        /// <param name="window">the containing window</param>
        /// <param name="criteria">the criteria to find the control</param>
        /// <returns>the found control. null - if not found</returns>
        public IUIItem FindControl(Window window, Dictionary <string, string> criteria)
        {
            // the "all" condition
            SearchCriteria crit = SearchCriteria.All;

            // for each criteria, AND with a new condition
            foreach (string key in criteria.Keys)
            {
                switch (key.ToLower())
                {
                //case Constants.PropertyNames.ControlType:
                //    crit = crit.AndControlType(GetTypeByName(criteria[key]));
                //    break;
                case Constants.PropertyNames.AutomationId:
                    crit = crit.AndAutomationId(criteria[key]);
                    break;

                case Constants.PropertyNames.Text:
                    crit = crit.AndByText(criteria[key]);
                    break;

                case Constants.PropertyNames.ClassName:
                    crit = crit.AndByClassName(criteria[key]);
                    break;

                case Constants.PropertyNames.Index:
                    crit = crit.AndIndex(int.Parse(criteria[key]));
                    break;

                default:
                {
                    bool bNativeFound          = false;
                    AutomationProperty[] props = window.AutomationElement.GetSupportedProperties();
                    foreach (AutomationProperty prop in props)
                    {
                        string propName = prop.ProgrammaticName.Substring(prop.ProgrammaticName.IndexOf('.') + 1);
                        propName = propName.Substring(0, propName.IndexOf("Property"));
                        if (propName.Equals(key, StringComparison.CurrentCultureIgnoreCase))
                        {
                            crit.AndNativeProperty(prop, criteria[key]);
                            bNativeFound = true;
                            break;
                        }
                    }
                    if (bNativeFound)
                    {
                        break;
                    }
                    ;
                }
                    return(null);
                }
                ;
            }

            try
            {
                // search for control with 'crit'
                IUIItem item = window.Get(crit, WaitTime);

                // return the found control
                return(item);
            }
            catch (Exception)
            {
                return(null);
            }
        }