示例#1
0
        /// <summary>
        /// Finds the control object from the descendants of specified control using the specified
        /// search configuration.
        /// </summary>
        /// <typeparam name="T">The type of control to find.</typeparam>
        /// <param name="self">The control whose descendants to search.</param>
        /// <param name="searchConfiguration">The search configuration.</param>
        /// <exception cref="InvalidSearchPropertyNamesException">
        /// Search configuration contains a property namely that isn't applicable on the control.
        /// </exception>
        public static T Find <T>(this UITestControl self, By searchConfiguration = null) where T : ControlBase
        {
            if (self == null)
            {
                throw new ArgumentNullException("self");
            }

            var control = ControlBaseFactory.Create <T>(searchConfiguration);

            // TODO: This assembly should have no knowledge of the Silverlight assembly
            if (typeof(T).Namespace.Equals("CUITe.Controls.SilverlightControls"))
            {
                control.SourceControl.Container = FindSilverlightContainer(self);
            }
            else if (typeof(T).Namespace.Equals(typeof(ComboBox).Namespace))
            {
                (control as ComboBox).SetWindow(FindBrowserWindow(self));
            }
            else
            {
                control.SourceControl.Container = self;
            }

            return(control);
        }
示例#2
0
 public void CreateWinControlsUsingParameterlessConstructor()
 {
     // Arrange
     foreach (Type controlType in ControlTypes.Where(x => typeof(WinControl).IsAssignableFrom(x)))
     {
         // Act (this code throws exception if the control cannot be created)
         ControlBaseFactory.Create(controlType);
     }
 }
示例#3
0
        public void CreateFromSourceControl()
        {
            foreach (Type sourceControlType in SourceControlTypes)
            {
                // Arrange
                var sourceControl = (UITestControl)Activator.CreateInstance(sourceControlType);

                // Act (this code throws exception if the control cannot be created)
                ControlBaseFactory.Create(sourceControl);
            }
        }
示例#4
0
        public void CreateUsingSearchProperties()
        {
            foreach (Type controlType in ControlTypes)
            {
                // Arrange
                By searchConfiguration = GetSearchPropertiesFor(controlType);

                // Act (this code throws exception if the control cannot be created)
                ControlBaseFactory.Create(controlType, searchConfiguration);
            }
        }
示例#5
0
        /// <summary>
        /// Finds the control object from the descendants of specified control using the specified
        /// search configuration.
        /// </summary>
        /// <typeparam name="T">The type of control to find.</typeparam>
        /// <param name="self">The control whose descendants to search.</param>
        /// <param name="searchConfiguration">The search configuration.</param>
        public static T Find <T>(this UITestControl self, By searchConfiguration = null) where T : ControlBase
        {
            if (self == null)
            {
                throw new ArgumentNullException("self");
            }

            T control;

            // TODO: This assembly should have no knowledge of the Silverlight assembly
            if (typeof(T).Namespace.Equals("CUITe.Controls.SilverlightControls"))
            {
                if (self is BrowserWindow)
                {
                    UITestControl silverlightObject = FindSilverlightContainer(self);
                    control = ControlBaseFactory.Create <T>(silverlightObject, searchConfiguration);
                }
                else
                {
                    control = ControlBaseFactory.Create <T>(self, searchConfiguration);
                }
            }
            else
            {
                control = ControlBaseFactory.Create <T>(searchConfiguration);

                if (typeof(T).Namespace.Equals(typeof(ComboBox).Namespace))
                {
                    (control as ComboBox).SetWindow(FindBrowserWindow(self));
                }
                else
                {
                    control.SourceControl.Container = self;

                    if ((searchConfiguration != null) &&
                        IsSubclassOfRawGeneric(typeof(WinControl <>), control.GetType()))
                    {
                        // Searching for WinForms controls differs slightly from searching for WPF controls.
                        // When searching for WPF controls using e.g. their automation id, the automation id
                        // search property is added to the WPF control.
                        // When searching for WinForms controls using their control name, the control name search
                        // property is added to the parent WinForms control, not the actual control itself.
                        control.SourceControl.Container.SearchProperties.AddRange(searchConfiguration.Configuration);
                    }
                }
            }

            return(control);
        }
示例#6
0
        /// <summary>
        /// Finds the control object from the descendants of specified control using the specified
        /// search configuration.
        /// </summary>
        /// <typeparam name="T">The type of control to find.</typeparam>
        /// <param name="self">The control whose descendants to search.</param>
        /// <param name="searchConfiguration">The search configuration.</param>
        public static T Find <T>(this UITestControl self, By searchConfiguration = null) where T : ControlBase
        {
            if (self == null)
            {
                throw new ArgumentNullException("self");
            }

            T control;

            // TODO: This assembly should have no knowledge of the Silverlight assembly
            if (typeof(T).Namespace.Equals("CUITe.Controls.SilverlightControls"))
            {
                if (self is BrowserWindow)
                {
                    UITestControl silverlightObject = FindSilverlightContainer(self);
                    control = ControlBaseFactory.Create <T>(silverlightObject, searchConfiguration);
                }
                else
                {
                    control = ControlBaseFactory.Create <T>(self, searchConfiguration);
                }
            }
            else
            {
                control = ControlBaseFactory.Create <T>(searchConfiguration);

                if (typeof(T).Namespace.Equals(typeof(ComboBox).Namespace))
                {
                    (control as ComboBox).SetWindow(FindBrowserWindow(self));
                }
                else
                {
                    control.SourceControl.Container = self;

                    if ((searchConfiguration != null) &&
                        IsSubclassOfRawGeneric(typeof(WinControl <>), control.GetType()))
                    {
                        control.SourceControl.SearchProperties.AddRange(searchConfiguration.Configuration);
                    }
                }
            }

            return(control);
        }
示例#7
0
        /// <summary>
        /// Finds the control object from the descendants of this control using the specified
        /// search configuration.
        /// </summary>
        /// <typeparam name="T">The type of control to find.</typeparam>
        /// <param name="searchConfiguration">The search configuration.</param>
        /// <exception cref="InvalidSearchPropertyNamesException">
        /// Search configuration contains a property namely that isn't applicable on the control.
        /// </exception>
        public T Find <T>(By searchConfiguration = null) where T : ControlBase
        {
            T control = ControlBaseFactory.Create <T>(searchConfiguration);

            if (typeof(T).Namespace.Equals("CUITe.Controls.SilverlightControls"))
            {
                control.SourceControl.Container = SilverlightObjectContainer;
            }
            else if (typeof(T).Namespace.Equals(typeof(ComboBox).Namespace))
            {
                (control as ComboBox).SetWindow(this);
            }
            else
            {
                control.SourceControl.Container = this;
            }

            return(control);
        }
示例#8
0
        /// <summary>
        /// Gets the CUITe control object when search parameters are passed.
        /// You don't have to create the object repository entry for this.
        /// </summary>
        /// <typeparam name="T">Pass the CUITe control you are looking for.</typeparam>
        /// <param name="searchParameters">In 'Key1=Value1;Key2=Value2' format. For example 'Id=firstname'</param>
        /// <returns>CUITe control object</returns>
        public T Get <T>(string searchParameters = null)
            where T : IControlBase
        {
            T control = ControlBaseFactory.Create <T>(searchParameters);

            if (typeof(T).Namespace.Equals("CUITe.Controls.SilverlightControls"))
            {
                var sourceControl = Activator.CreateInstance(control.SourceType, SlObjectContainer);
                control.Wrap(sourceControl);
            }
            else if (typeof(T).Namespace.Equals("CUITe.Controls.TelerikControls"))
            {
                (control as ComboBox).SetWindow(this);
            }
            else
            {
                var sourceControl = Activator.CreateInstance(control.SourceType, this);
                control.Wrap(sourceControl);
            }

            return(control);
        }
示例#9
0
        private T GetCell <T>(int iRow, int iCol) where T : ControlBase, IHasInnerText
        {
            WaitForControlReady();
            UITestControl htmlCell = null;
            int           rowCount = -1;

            foreach (UITestControl row in SourceControl.Rows)
            {
                //control could be of ControlType.RowHeader or ControlType.Row

                rowCount++;
                if (rowCount != iRow)
                {
                    continue;
                }

                int colCount = -1;

                foreach (UITestControl cell in row.GetChildren()) //Cells could be a collection of HtmlCell and HtmlHeaderCell controls
                {
                    colCount++;
                    if (colCount != iCol)
                    {
                        continue;
                    }

                    htmlCell = cell;
                    break;
                }

                if (htmlCell != null)
                {
                    break;
                }
            }

            return(ControlBaseFactory.Create <T>(htmlCell, null));
        }