Beispiel #1
0
        /// <summary>
        /// Configures the specified search properties.
        /// </summary>
        /// <param name="searchProperties">The search properties.</param>
        public void Configure(PropertyExpressionCollection searchProperties)
        {
            if (searchProperties == null)
                throw new ArgumentNullException("searchProperties");

            searchProperties.Add(this.propertyName, this.propertyValue, this.conditionOperator);
        }
        /// <summary>
        /// Configures the specified search properties.
        /// </summary>
        /// <param name="searchProperties">The search properties.</param>
        public void Configure(PropertyExpressionCollection searchProperties)
        {
            if (searchProperties == null)
                throw new ArgumentNullException("searchProperties");

            searchProperties.Add(WpfControl.PropertyNames.AutomationId, automationId, conditionOperator);
        }
        public PropertyExpressionCollection ToPropertyCollection( )
        {
            var resultCollection = new PropertyExpressionCollection();
            var type = typeof(WebControl);

            var properties = type.GetProperties();

            var propertyValue = string.Empty;
            foreach (var property in properties)
            {
                propertyValue = property.GetValue(this, null) as string;
                if (!string.IsNullOrWhiteSpace(propertyValue))
                {
                    if (propertyValue.Contains('*'))
                    {
                        propertyValue = propertyValue.Replace("*", string.Empty);
                        resultCollection.Add(property.Name, propertyValue, PropertyExpressionOperator.Contains);
                    }
                    else
                    {
                        resultCollection.Add(property.Name, propertyValue, PropertyExpressionOperator.EqualTo);
                    }
                }
            }

            return resultCollection;
        }
        internal HtmlHyperlink NugetSubLink1(string innerText)
        {
            var searchConditions = new PropertyExpressionCollection
            {
                new PropertyExpression(HtmlControl.PropertyNames.Class, "nrgt", PropertyExpressionOperator.EqualTo)
            };
            var nugetResultTable = Window.Find<HtmlTable>(searchConditions);

            foreach (HtmlRow row in nugetResultTable.Rows)
            {
                foreach (HtmlCell cell in row.Cells)
                {
                    var condition = new PropertyExpressionCollection
                    {
                        new PropertyExpression(HtmlControl.PropertyNames.Class, "l",
                            PropertyExpressionOperator.EqualTo),
                        new PropertyExpression(HtmlControl.PropertyNames.InnerText, innerText,
                            PropertyExpressionOperator.EqualTo)
                    };
                    var link = cell.Find<HtmlHyperlink>(condition);
                    if (link.Exists)
                    {
                        return link;
                    }
                }
            }
            return null;
        }
Beispiel #5
0
        /// <summary>
        /// Configures the specified search properties.
        /// </summary>
        /// <param name="searchProperties">The search properties.</param>
        public void Configure(PropertyExpressionCollection searchProperties)
        {
            if (searchProperties == null)
                throw new ArgumentNullException("searchProperties");

            searchProperties.Add(HtmlControl.PropertyNames.TagName, tagName, conditionOperator);
        }
 public HtmlDiv LogoDiv()
 {
     var searchConditions = new PropertyExpressionCollection
     {
         new PropertyExpression(HtmlControl.PropertyNames.Id, "logo", PropertyExpressionOperator.EqualTo)
     };
     return Window.Find<HtmlDiv>(searchConditions);
 }
 internal HtmlHyperlink NugetSiteLink()
 {
     var searchConditions = new PropertyExpressionCollection
     {
         new PropertyExpression("href", "https://www.nuget.org", PropertyExpressionOperator.Contains)
     };
     return Window.Find<HtmlHyperlink>(searchConditions);
 }
 internal HtmlDiv SearchBox()
 {
     var searchConditions = new PropertyExpressionCollection
     {
         new PropertyExpression(HtmlControl.PropertyNames.Id, "sb_ifc0", PropertyExpressionOperator.EqualTo),
         new PropertyExpression(HtmlControl.PropertyNames.Class, "sbib_b", PropertyExpressionOperator.EqualTo)
     };
     return Window.Find<HtmlDiv>(searchConditions);
 }
 internal HtmlControl SearchButton()
 {
     var searchConditions = new PropertyExpressionCollection
     {
         new PropertyExpression(HtmlControl.PropertyNames.Name, "btnG", PropertyExpressionOperator.EqualTo),
         new PropertyExpression(HtmlControl.PropertyNames.TagName, "button", PropertyExpressionOperator.EqualTo)
     };
     return Window.Find(searchConditions);
 }
Beispiel #10
0
        public void ConfigureStrict()
        {
            // Arrange
            var configurator = (ISearchConfigurator)Activator.CreateInstance(this.type, BindingFlags, null, new object[]{ this.propertyValue, PropertyExpressionOperator.EqualTo }, null);
            var searchProperties = new PropertyExpressionCollection();

            // Act
            configurator.Configure(searchProperties);

            // Assert
            Assert.AreEqual(1, searchProperties.Count);
            Assert.AreEqual(this.propertyValue, searchProperties.Find(this.propertyName).PropertyValue);
            Assert.AreEqual(PropertyExpressionOperator.EqualTo, searchProperties.Find(this.propertyName).PropertyOperator);
        }
        public void ConfigureLoose()
        {
            // Arrange
            var configurator = new AutomationIdConfigurator("SomeId", PropertyExpressionOperator.Contains);
            var searchProperties = new PropertyExpressionCollection();

            // Act
            configurator.Configure(searchProperties);

            // Assert
            Assert.AreEqual(1, searchProperties.Count);
            Assert.AreEqual("SomeId", searchProperties.Find("AutomationId").PropertyValue);
            Assert.AreEqual(PropertyExpressionOperator.Contains, searchProperties.Find("AutomationId").PropertyOperator);
        }
Beispiel #12
0
        public void ConfigureStrict()
        {
            // Arrange
            var configurator = new ClassConfigurator("SomeClass", PropertyExpressionOperator.EqualTo);
            var searchProperties = new PropertyExpressionCollection();

            // Act
            configurator.Configure(searchProperties);

            // Assert
            Assert.AreEqual(1, searchProperties.Count);
            Assert.AreEqual("SomeClass", searchProperties.Find("Class").PropertyValue);
            Assert.AreEqual(PropertyExpressionOperator.EqualTo, searchProperties.Find("Class").PropertyOperator);
        }
        public void ConfigureLooseSearchProperty()
        {
            // Arrange
            var configurator = new SearchPropertiesConfigurator("Name~Value");
            var searchProperties = new PropertyExpressionCollection();

            // Act
            configurator.Configure(searchProperties);

            // Assert
            Assert.AreEqual(1, searchProperties.Count);
            Assert.AreEqual("Value", searchProperties.Find("Name").PropertyValue);
            Assert.AreEqual(PropertyExpressionOperator.Contains, searchProperties.Find("Name").PropertyOperator);
        }
 internal HtmlHyperlink NugetSubLink2(string innerText)
 {
     var searchConditions = new PropertyExpressionCollection
     {
         new PropertyExpression(HtmlControl.PropertyNames.Class, "nrgt", PropertyExpressionOperator.EqualTo)
     };
     var nugetResultTable = Window.Find<HtmlTable>(searchConditions);
     var condition = new PropertyExpressionCollection
             {
                 new PropertyExpression(HtmlControl.PropertyNames.Class, "l",
                     PropertyExpressionOperator.EqualTo),
                 new PropertyExpression(HtmlControl.PropertyNames.InnerText, innerText,
                     PropertyExpressionOperator.EqualTo)
             };
     return nugetResultTable.Find<HtmlHyperlink>(condition);
 }
        public void ConfigureStrictSearchProperties()
        {
            // Arrange
            var configurator = new SearchPropertiesConfigurator("Name1=Value1;Name2=Value2");
            var searchProperties = new PropertyExpressionCollection();

            // Act
            configurator.Configure(searchProperties);

            // Assert
            Assert.AreEqual(2, searchProperties.Count);
            Assert.AreEqual("Value1", searchProperties.Find("Name1").PropertyValue);
            Assert.AreEqual(PropertyExpressionOperator.EqualTo, searchProperties.Find("Name1").PropertyOperator);
            Assert.AreEqual("Value2", searchProperties.Find("Name2").PropertyValue);
            Assert.AreEqual(PropertyExpressionOperator.EqualTo, searchProperties.Find("Name2").PropertyOperator);
        }
 internal HtmlHyperlink NugetSubLink3(string innerText)
 {
     var bigDivSearch = new PropertyExpressionCollection
     {
         new PropertyExpression(HtmlControl.PropertyNames.Id, "cnt", PropertyExpressionOperator.EqualTo),
         new PropertyExpression(HtmlControl.PropertyNames.Class, "big", PropertyExpressionOperator.EqualTo)
     };
     var bigDiv = Window.Find<HtmlDiv>(bigDivSearch);
     var resultsDivSearch = new PropertyExpressionCollection
     {
         new PropertyExpression(HtmlControl.PropertyNames.Class, "mw", PropertyExpressionOperator.EqualTo)
     };
     var resultsDiv = bigDiv.Find<HtmlDiv>(resultsDivSearch);
     var rcntDivSearch = new PropertyExpressionCollection
     {
         new PropertyExpression(HtmlControl.PropertyNames.Id, "rcnt", PropertyExpressionOperator.EqualTo)
     };
     var rcntDiv = resultsDiv.Find<HtmlDiv>(rcntDivSearch);
     var centerColDivSearch = new PropertyExpressionCollection
     {
         new PropertyExpression(HtmlControl.PropertyNames.Id, "center_col", PropertyExpressionOperator.EqualTo)
     };
     var centerColDiv = rcntDiv.Find<HtmlDiv>(centerColDivSearch);
     var searchDivSearch = new PropertyExpressionCollection
     {
         new PropertyExpression(HtmlControl.PropertyNames.Id, "search", PropertyExpressionOperator.EqualTo)
     };
     var searchDiv = centerColDiv.Find<HtmlDiv>(searchDivSearch);
     var iresDivSearch = new PropertyExpressionCollection
     {
         new PropertyExpression(HtmlControl.PropertyNames.Id, "ires", PropertyExpressionOperator.EqualTo)
     };
     var iresDiv = searchDiv.Find<HtmlDiv>(iresDivSearch);
     var searchConditions = new PropertyExpressionCollection
     {
         new PropertyExpression(HtmlControl.PropertyNames.Class, "nrgt", PropertyExpressionOperator.EqualTo)
     };
     var nugetResultTable = iresDiv.Find<HtmlTable>(searchConditions);
     var condition = new PropertyExpressionCollection
             {
                 new PropertyExpression(HtmlControl.PropertyNames.Class, "l",
                     PropertyExpressionOperator.EqualTo),
                 new PropertyExpression(HtmlControl.PropertyNames.InnerText, innerText,
                     PropertyExpressionOperator.EqualTo)
             };
     return nugetResultTable.Find<HtmlHyperlink>(condition);
 }
Beispiel #17
0
        /// <summary>
        /// Moves the property expressions with property name
        /// <see cref="CUITControls.WinControl.PropertyNames.ControlName"/>. from the control to
        /// search for to its parent.
        /// </summary>
        private void MoveControlNames(PropertyExpressionCollection searchProperties)
        {
            PropertyExpression[] controlNameExpressions = searchProperties
                                                          .Where(searchProperty => searchProperty.PropertyName == CUITControls.WinControl.PropertyNames.ControlName)
                                                          .ToArray();

            if (!controlNameExpressions.Any())
            {
                return;
            }

            foreach (PropertyExpression controlNameExpression in controlNameExpressions)
            {
                searchProperties.Remove(controlNameExpression);
            }

            SourceControl.SearchProperties.AddRange(controlNameExpressions);
        }
Beispiel #18
0
        /// <summary>
        /// Configures the specified search properties.
        /// </summary>
        /// <param name="searchProperties">The search properties.</param>
        /// <exception cref="InvalidSearchPropertiesFormatException">
        /// Format of search properties is invalid.
        /// </exception>
        public void Configure(PropertyExpressionCollection searchProperties)
        {
            if (searchProperties == null)
            {
                throw new ArgumentNullException("searchProperties");
            }

            // Split on groups of name/value pairs
            string[] nameValuePairs = this.searchProperties.Split(
                new[] { ';' },
                StringSplitOptions.RemoveEmptyEntries);

            foreach (string nameValuePair in nameValuePairs)
            {
                var compareOperator = PropertyExpressionOperator.EqualTo;

                // If split on '=' does not work, then try '~'
                // Split at the first instance of '='. Other instances are considered part of the value.
                string[] splittedNameValuePair = nameValuePair.Split(
                    new[] { '=' },
                    2);

                if (splittedNameValuePair.Length != 2)
                {
                    // Otherwise try to split on '~'. If it works then compare type is Contains
                    // Split at the first instance of '~'. Other instances are considered part of the value.
                    splittedNameValuePair = nameValuePair.Split(
                        new[] { '~' },
                        2);

                    if (splittedNameValuePair.Length == 2)
                    {
                        compareOperator = PropertyExpressionOperator.Contains;
                    }
                    else
                    {
                        throw new InvalidSearchPropertiesFormatException(this.searchProperties);
                    }
                }

                // Add the search property, value and type
                searchProperties.Add(splittedNameValuePair[0], splittedNameValuePair[1], compareOperator);
            }
        }
        /// <summary>
        /// Configures the specified search properties.
        /// </summary>
        /// <param name="searchProperties">The search properties.</param>
        /// <exception cref="InvalidSearchPropertiesFormatException">
        /// Format of search properties is invalid.
        /// </exception>
        public void Configure(PropertyExpressionCollection searchProperties)
        {
            if (searchProperties == null)
                throw new ArgumentNullException("searchProperties");

            // Split on groups of name/value pairs
            string[] nameValuePairs = this.searchProperties.Split(
                new[] { ';' },
                StringSplitOptions.RemoveEmptyEntries);

            foreach (string nameValuePair in nameValuePairs)
            {
                var compareOperator = PropertyExpressionOperator.EqualTo;

                // If split on '=' does not work, then try '~'
                // Split at the first instance of '='. Other instances are considered part of the value.
                string[] splittedNameValuePair = nameValuePair.Split(
                    new[] { '=' },
                    2);

                if (splittedNameValuePair.Length != 2)
                {
                    // Otherwise try to split on '~'. If it works then compare type is Contains
                    // Split at the first instance of '~'. Other instances are considered part of the value.
                    splittedNameValuePair = nameValuePair.Split(
                        new[] { '~' },
                        2);

                    if (splittedNameValuePair.Length == 2)
                    {
                        compareOperator = PropertyExpressionOperator.Contains;
                    }
                    else
                    {
                        throw new InvalidSearchPropertiesFormatException(this.searchProperties);
                    }
                }

                // Add the search property, value and type
                searchProperties.Add(splittedNameValuePair[0], splittedNameValuePair[1], compareOperator);
            }
        }
Beispiel #20
0
        /// <summary>
        /// Click the specific messagebox button
        /// </summary>
        /// <param name="buttonName">The messagebox button's name</param>
        /// <param name="title">The messagebox's title</param>
        /// <exception cref="Exception">If the control is not found</exception>
        public static void ClickMessageBoxButton(string title, string buttonName)
        {
            ApplicationUnderTest         messageBox = new ApplicationUnderTest();
            PropertyExpressionCollection properties = new PropertyExpressionCollection();

            properties.Add(UITestControl.PropertyNames.TechnologyName, MSAA_TECHNOLOGY);
            properties.Add(UITestControl.PropertyNames.ControlType, "Window");
            properties.Add(UITestControl.PropertyNames.Name, title);
            messageBox.SearchProperties.AddRange(properties);
            messageBox.Find();
            UITestControl button = new UITestControl(messageBox);
            PropertyExpressionCollection properties2 = new PropertyExpressionCollection();

            properties2.Add(UITestControl.PropertyNames.TechnologyName, MSAA_TECHNOLOGY);
            properties2.Add(UITestControl.PropertyNames.ControlType, "Button");
            properties2.Add(UITestControl.PropertyNames.Name, buttonName);
            button.SearchProperties.AddRange(properties2);
            button.Find();
            Mouse.Click(button);
        }
Beispiel #21
0
        protected ControlBase(string searchProperties)
        {
            this.searchProperties = new PropertyExpressionCollection();

            SetSearchProperties(searchProperties);
        }
Beispiel #22
0
 /// <summary>
 /// Sets the property.
 /// </summary>
 /// <param name="collection">The collection.</param>
 /// <param name="key">The key.</param>
 /// <param name="value">The value.</param>
 private static void SetProperty(PropertyExpressionCollection collection, string key, string value)
 {
     SetProperty(null, collection, key, value);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="JQuerySelector" /> class.
 /// </summary>
 /// <param name="searchProperties">Collection of search properties</param>
 /// <param name="filterProperties">Collection of filter properties</param>
 public JQuerySelector(PropertyExpressionCollection searchProperties, PropertyExpressionCollection filterProperties)
 {
     this.searchProperties = searchProperties;
     this.filterProperties = filterProperties;
 }
 /// <summary>
 /// Creates a search control that finds the first child control
 /// of type T from the given parent that matches the given
 /// property expression collection
 /// </summary>
 /// <typeparam name="T">
 /// The type of control to find
 /// </typeparam>
 /// <param name="parent">
 /// The UITestControl from which to start searching
 /// </param>
 /// <param name="expressions">
 /// The search expressions to match when searching
 /// </param>
 /// <returns>
 /// A search control that finds the first child control
 /// of type T from the given parent that matches the given
 /// property expression collection
 /// </returns>
 public static T Find <T>(this UITestControl parent, PropertyExpressionCollection expressions) where T : UITestControl, new()
 {
     return(parent.Find <T>().Extend(expressions));
 }
 /// <summary>
 /// Creates a search control that will find all children of the
 /// specified type matching the property expression collection
 /// </summary>
 /// <typeparam name="T">
 /// Type of control to find
 /// </typeparam>
 /// <param name="parent">
 /// The UITestControl from which to start searching
 /// </param>
 /// <param name="expressions">
 /// The search expressions to match when searching
 /// </param>
 /// <returns>
 /// A search control that will find all children of the
 /// specified type matching the property expression collection
 /// </returns>
 public static IEnumerable <T> FindAll <T>(this UITestControl parent, PropertyExpressionCollection expressions) where T : UITestControl, new()
 {
     return(parent.Find <T>(expressions).FindAllAsType());
 }
 /// <summary>
 /// Extends the search properties of the current UITestControl
 /// and returns that search control with the additional property
 /// </summary>
 /// <typeparam name="T">
 /// Type of control to find
 /// </typeparam>
 /// <param name="current">
 /// The UITestControl to extend
 /// </param>
 /// <param name="expressions">
 /// The search expressions to match when searching
 /// </param>
 /// <returns>
 /// The current UITestControl with the additional search property
 /// </returns>
 public static T Extend <T>(this T current, PropertyExpressionCollection expressions) where T : UITestControl
 {
     current.SearchProperties.AddRange(expressions);
     return(current);
 }
Beispiel #27
0
 public EnhancedControlBase()
 {
     this.SearchProperties = new PropertyExpressionCollection();
 }
Beispiel #28
0
        public static TControl Find <TControl>(this UITestControl container, PropertyExpressionCollection searchProperties, PropertyExpressionCollection filterProperties = null)
            where TControl : HtmlControl, new()
        {
            var control = new TControl {
                Container = container
            };

            control.SearchProperties.AddRange(searchProperties);
            if (filterProperties != null)
            {
                control.FilterProperties.AddRange(filterProperties);
            }
            return(control);
        }
        protected string BuildSelector(PropertyExpressionCollection propertyExpressions)
        {
            string        tagName         = string.Empty;
            string        explicitParent  = string.Empty;
            List <string> contentFilters  = new List <string>();
            List <string> functionFilters = new List <string>();
            List <string> methods         = new List <string>();
            List <string> attributes      = new List <string>();

            foreach (PropertyExpression propertyExpression in propertyExpressions)
            {
                if (propertyExpression.PropertyName.Equals(UITestControl.PropertyNames.TagName))
                {
                    tagName = propertyExpression.PropertyValue;
                    continue;
                }

                if (RulesDictionary.ContainsKey(propertyExpression.PropertyName))
                {
                    SelectorPart selectorPart = RulesDictionary[propertyExpression.PropertyName].Invoke(propertyExpression);

                    switch (selectorPart.Filter)
                    {
                    case SelectorPart.FilterType.ContentFilter:
                        contentFilters.Add(selectorPart.Value);
                        break;

                    case SelectorPart.FilterType.FunctionFilter:
                        functionFilters.Add(selectorPart.Value);
                        break;

                    case SelectorPart.FilterType.Method:
                        methods.Add(selectorPart.Value);
                        break;

                    case SelectorPart.FilterType.ExplicitParent:
                        explicitParent = selectorPart.Value;
                        break;
                    }
                }
                else
                {
                    string containsSign = propertyExpression.PropertyOperator == PropertyExpressionOperator.Contains ? "*" : string.Empty;
                    string attribute    = string.Format(
                        "[{0}{1}={2}]", propertyExpression.PropertyName, containsSign, propertyExpression.PropertyValue);
                    attributes.Add(attribute);
                }
            }

            string filter = string.Empty;

            if (functionFilters.Count != 0)
            {
                string functionTemplate = ".filter(function() { return %scriptStatements%;})";
                filter = functionTemplate.Replace("%scriptStatements%", string.Join(" && ", functionFilters));
            }

            string selector = string.Format(
                "jQuery(\"{0}{1}{2}\"%parent%){3}{4}",
                tagName,
                string.Join(string.Empty, attributes),
                string.Join(string.Empty, contentFilters),
                filter,
                string.Join(string.Empty, methods));

            if (!string.IsNullOrEmpty(explicitParent))
            {
                selector = selector.Replace("%parent%", explicitParent);
            }

            return(selector);
        }