상속: System.Attribute
예제 #1
0
        protected virtual By BuildBy(FindsByAttribute findsBy)
        {
            How how = findsBy.How;
            string usingStr = findsBy.Using;
            Type customType = findsBy.CustomFinderType;

            switch (how)
            {
                case How.Id:
                    return By.Id(usingStr);
                case How.Name:
                    return By.Name(usingStr);
                case How.TagName:
                    return By.TagName(usingStr);
                case How.ClassName:
                    return By.ClassName(usingStr);
                case How.CssSelector:
                    return By.CssSelector(usingStr);
                case How.LinkText:
                    return By.LinkText(usingStr);
                case How.PartialLinkText:
                    return By.PartialLinkText(usingStr);
                case How.XPath:
                    return By.XPath(usingStr);
                case How.Custom:
                    ConstructorInfo ctor = customType.GetConstructor(new Type[] { typeof(string) });
                    By finder = ctor.Invoke(new object[] { usingStr }) as By;
                    return finder;
                default:
                    throw new ArgumentException(string.Format("Did not know how to construct How from how {0}, using {1}", how, usingStr));
            }
        }
예제 #2
0
        /// <summary>
        /// Determines whether the specified <see cref="System.Object">Object</see> is equal
        /// to the current <see cref="System.Object">Object</see>.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object">Object</see> to compare with the
        /// current <see cref="System.Object">Object</see>.</param>
        /// <returns><see langword="true"/> if the specified <see cref="System.Object">Object</see>
        /// is equal to the current <see cref="System.Object">Object</see>; otherwise,
        /// <see langword="false"/>.</returns>
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            FindsByAttribute other = obj as FindsByAttribute;

            if (other == null)
            {
                return(false);
            }

            if (other.Priority != this.Priority)
            {
                return(false);
            }

            if (other.Finder != this.Finder)
            {
                return(false);
            }

            return(true);
        }
 /// <summary>
 /// Gets the locator from the attribute.
 /// </summary>
 /// <param name="attribute">The attribute.</param>
 /// <returns>The created locator; otherwise <c>null</c>.</returns>
 public static By GetLocator(FindsByAttribute attribute)
 {
     var how = attribute.How;
     var usingValue = attribute.Using;
     switch (how)
     {
         case How.Id:
             return By.Id(usingValue);
         case How.Name:
             return By.Name(usingValue);
         case How.TagName:
             return By.TagName(usingValue);
         case How.ClassName:
             return By.ClassName(usingValue);
         case How.CssSelector:
             return By.CssSelector(usingValue);
         case How.LinkText:
             return By.LinkText(usingValue);
         case How.PartialLinkText:
             return By.PartialLinkText(usingValue);
         case How.XPath:
             return By.XPath(usingValue);
         default:
             return null;
     }
 }
예제 #4
0
 private static By From(FindsByAttribute attribute)
 {
     Assembly assembly = Assembly.LoadFrom("WebDriver.Support.dll");
     Type seleniumByFactory = assembly.GetType("OpenQA.Selenium.Support.PageObjects.ByFactory");
     MethodInfo m = seleniumByFactory.GetMethod("From", new Type[] { typeof(FindsByAttribute) });
     return (By)m.Invoke(seleniumByFactory, new object[] { attribute });
 }
예제 #5
0
 public void TestComparison()
 {
     FindsByAttribute first = new FindsByAttribute() { How = How.Id, Using = "Test", Priority = 1 };
     FindsByAttribute second = new FindsByAttribute() { How = How.Id, Using = "Test", Priority = 2 };
     Assert.Less(first, second);
     Assert.Greater(second, first);
 }
예제 #6
0
        /// <summary>
        /// Gets an instance of the <see cref="By"/> class based on the specified attribute.
        /// </summary>
        /// <param name="attribute">The <see cref="FindsByAttribute"/> describing how to find the element.</param>
        /// <returns>An instance of the <see cref="By"/> class.</returns>
        public static By From(FindsByAttribute attribute)
        {
            var how        = attribute.How;
            var usingValue = attribute.Using;

            switch (how)
            {
            case How.Id:
                return(By.Id(usingValue));

            case How.Name:
                return(By.Name(usingValue));

            case How.TagName:
                return(By.TagName(usingValue));

            case How.ClassName:
                return(By.ClassName(usingValue));

            case How.CssSelector:
                return(By.CssSelector(usingValue));

            case How.LinkText:
                return(By.LinkText(usingValue));

            case How.PartialLinkText:
                return(By.PartialLinkText(usingValue));

            case How.XPath:
                return(By.XPath(usingValue));
            }

            throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Did not know how to construct How from how {0}, using {1}", how, usingValue));
        }
예제 #7
0
        /// <summary>
        /// Gets an instance of the <see cref="By"/> class based on the specified attribute.
        /// </summary>
        /// <param name="attribute">The <see cref="FindsByAttribute"/> describing how to find the element.</param>
        /// <returns>An instance of the <see cref="By"/> class.</returns>
        public static By From(FindsByAttribute attribute)
        {
            var how = attribute.How;
            var usingValue = attribute.Using;
            switch (how)
            {
                case How.Id:
                    return By.Id(usingValue);
                case How.Name:
                    return By.Name(usingValue);
                case How.TagName:
                    return By.TagName(usingValue);
                case How.ClassName:
                    return By.ClassName(usingValue);
                case How.CssSelector:
                    return By.CssSelector(usingValue);
                case How.LinkText:
                    return By.LinkText(usingValue);
                case How.PartialLinkText:
                    return By.PartialLinkText(usingValue);
                case How.XPath:
                    return By.XPath(usingValue);
            }

            throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Did not know how to construct How from how {0}, using {1}", how, usingValue));
        }
예제 #8
0
 public void TestInequalityOfPriority()
 {
     FindsByAttribute first = new FindsByAttribute() { How = How.Id, Using = "Test", Priority = 1 };
     FindsByAttribute second = new FindsByAttribute() { How = How.Id, Using = "Test", Priority = 2 };
     Assert.IsFalse(first.Equals(second));
     Assert.IsFalse(first == second);
     Assert.IsTrue(first != second);
 }
        public void TestLocatorCreateCssSelector()
        {
            var attribute = new FindsByAttribute { How = How.CssSelector, Using = "btn" };

            var locator = NativeAttributeBuilder.GetLocator(attribute);

            Assert.AreEqual(By.CssSelector("btn"), locator);
        }
        public void TestLocatorCreateTagName()
        {
            var attribute = new FindsByAttribute { How = How.TagName, Using = "div" };

            var locator = NativeAttributeBuilder.GetLocator(attribute);

            Assert.AreEqual(By.TagName("div"), locator);
        }
        public void TestLocatorCreateId()
        {
            var attribute = new FindsByAttribute { How = How.Id, Using = "Foo" };

            var locator = NativeAttributeBuilder.GetLocator(attribute);

            Assert.AreEqual(By.Id("Foo"), locator);
        }
예제 #12
0
 public void TestInequalityOfUsing()
 {
     FindsByAttribute first = new FindsByAttribute() { How = How.Id, Using = "Hello" };
     FindsByAttribute second = new FindsByAttribute() { How = How.Id, Using = "World" };
     Assert.IsFalse(first.Equals(second));
     Assert.IsFalse(first == second);
     Assert.IsTrue(first != second);
 }
예제 #13
0
 public void TestEquality()
 {
     FindsByAttribute first = new FindsByAttribute() { How = How.Id, Using = "Test" };
     FindsByAttribute second = new FindsByAttribute() { How = How.Id, Using = "Test" };
     Assert.IsTrue(first.Equals(second));
     Assert.IsFalse(object.ReferenceEquals(first, second));
     Assert.IsTrue(first == second);
     Assert.IsFalse(first != second);
 }
예제 #14
0
 public void TestSameInstanceEquality()
 {
     FindsByAttribute first = new FindsByAttribute() { How = How.Id, Using = "Test" };
     FindsByAttribute second = first;
     Assert.IsTrue(first == second);
     Assert.IsTrue(second == first);
     Assert.IsTrue(first.Equals(second));
     Assert.IsTrue(second.Equals(first));
     Assert.IsTrue(object.ReferenceEquals(first, second));
 }
예제 #15
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            FindsByAttribute findsByAttribute = obj as FindsByAttribute;

            return(!(findsByAttribute == null) && findsByAttribute.Priority == this.Priority && !(findsByAttribute.Finder != this.Finder));
        }
예제 #16
0
        /// <summary>
        /// Gets an instance of the <see cref="By"/> class based on the specified attribute.
        /// </summary>
        /// <param name="attribute">The <see cref="FindsByAttribute"/> describing how to find the element.</param>
        /// <returns>An instance of the <see cref="By"/> class.</returns>
        public static By From(FindsByAttribute attribute)
        {
            var how        = attribute.How;
            var usingValue = attribute.Using;

            switch (how)
            {
            case How.Id:
                return(By.Id(usingValue));

            case How.Name:
                return(By.Name(usingValue));

            case How.TagName:
                return(By.TagName(usingValue));

            case How.ClassName:
                return(By.ClassName(usingValue));

            case How.CssSelector:
                return(By.CssSelector(usingValue));

            case How.LinkText:
                return(By.LinkText(usingValue));

            case How.PartialLinkText:
                return(By.PartialLinkText(usingValue));

            case How.XPath:
                return(By.XPath(usingValue));

            case How.Custom:
                if (attribute.CustomFinderType == null)
                {
                    throw new ArgumentException("Cannot use How.Custom without supplying a custom finder type");
                }

                if (!attribute.CustomFinderType.IsSubclassOf(typeof(By)))
                {
                    throw new ArgumentException("Custom finder type must be a descendent of the By class");
                }

                ConstructorInfo ctor = attribute.CustomFinderType.GetConstructor(new Type[] { typeof(string) });
                if (ctor == null)
                {
                    throw new ArgumentException("Custom finder type must expose a public constructor with a string argument");
                }

                By finder = ctor.Invoke(new object[] { usingValue }) as By;
                return(finder);
            }

            throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Did not know how to construct How from how {0}, using {1}", how, usingValue));
        }
예제 #17
0
        public void TestEqualityOfTwoNullInstances()
        {
            FindsByAttribute first  = null;
            FindsByAttribute second = null;

            // Must test order of arguments for overridden operators
            Assert.IsTrue(first == second);
            Assert.IsFalse(first != second);
            Assert.IsTrue(second == first);
            Assert.IsFalse(second != first);
        }
예제 #18
0
        public void TestInequalityOfNull()
        {
            FindsByAttribute first = new FindsByAttribute() { How = How.Id, Using = "Test" };
            FindsByAttribute second = null;
            Assert.IsFalse(first.Equals(second));

            // Must test order of arguments for overridden operators
            Assert.IsFalse(first == second);
            Assert.IsTrue(first != second);
            Assert.IsFalse(second == first);
            Assert.IsTrue(second != first);
        }
예제 #19
0
        protected virtual By BuildByFromFindsBys(FindsByAttribute[] findBys)
        {
            AssertValidFindBys(findBys);

            By[] byArray = new By[findBys.Length];
            for (int i = 0; i < findBys.Length; i++)
            {
                byArray[i] = BuildByFromFindsBy(findBys[i]);
            }

            return new ByChained(byArray);
        }
예제 #20
0
        public void TestSameInstanceEquality()
        {
            FindsByAttribute first = new FindsByAttribute()
            {
                How = How.Id, Using = "Test"
            };
            FindsByAttribute second = first;

            Assert.IsTrue(first == second);
            Assert.IsTrue(second == first);
            Assert.IsTrue(first.Equals(second));
            Assert.IsTrue(second.Equals(first));
            Assert.IsTrue(object.ReferenceEquals(first, second));
        }
예제 #21
0
        public void TestComparison()
        {
            FindsByAttribute first = new FindsByAttribute()
            {
                How = How.Id, Using = "Test", Priority = 1
            };
            FindsByAttribute second = new FindsByAttribute()
            {
                How = How.Id, Using = "Test", Priority = 2
            };

            Assert.Less(first, second);
            Assert.Greater(second, first);
        }
예제 #22
0
        public void TestInequalityOfPriority()
        {
            FindsByAttribute first = new FindsByAttribute()
            {
                How = How.Id, Using = "Test", Priority = 1
            };
            FindsByAttribute second = new FindsByAttribute()
            {
                How = How.Id, Using = "Test", Priority = 2
            };

            Assert.IsFalse(first.Equals(second));
            Assert.IsFalse(first == second);
            Assert.IsTrue(first != second);
        }
예제 #23
0
        public void TestInequalityOfUsing()
        {
            FindsByAttribute first = new FindsByAttribute()
            {
                How = How.Id, Using = "Hello"
            };
            FindsByAttribute second = new FindsByAttribute()
            {
                How = How.Id, Using = "World"
            };

            Assert.IsFalse(first.Equals(second));
            Assert.IsFalse(first == second);
            Assert.IsTrue(first != second);
        }
예제 #24
0
        protected static ReadOnlyCollection <By> CreateLocatorList(MemberInfo member)
        {
            if (member == null)
            {
                throw new ArgumentNullException("member", "memeber cannot be null");
            }
            Attribute[] customAttributes = Attribute.GetCustomAttributes(member, typeof(FindsBySequenceAttribute), true);
            bool        flag             = customAttributes.Length > 0;

            Attribute[] customAttributes2 = Attribute.GetCustomAttributes(member, typeof(FindsByAllAttribute), true);
            bool        flag2             = customAttributes2.Length > 0;

            if (flag && flag2)
            {
                throw new ArgumentException("Cannot specify FindsBySequence and FindsByAll on the same member");
            }
            List <By> list = new List <By>();

            Attribute[] customAttributes3 = Attribute.GetCustomAttributes(member, typeof(FindsByAttribute), true);
            if (customAttributes3.Length > 0)
            {
                Array.Sort <Attribute>(customAttributes3);
                Attribute[] array = customAttributes3;
                for (int i = 0; i < array.Length; i++)
                {
                    Attribute        attribute        = array[i];
                    FindsByAttribute findsByAttribute = (FindsByAttribute)attribute;
                    if (findsByAttribute.Using == null)
                    {
                        findsByAttribute.Using = member.Name;
                    }
                    list.Add(findsByAttribute.Finder);
                }
                if (flag)
                {
                    ByChained item = new ByChained(list.ToArray());
                    list.Clear();
                    list.Add(item);
                }
                if (flag2)
                {
                    ByAll item2 = new ByAll(list.ToArray());
                    list.Clear();
                    list.Add(item2);
                }
            }
            return(list.AsReadOnly());
        }
예제 #25
0
        public void TestEquality()
        {
            FindsByAttribute first = new FindsByAttribute()
            {
                How = How.Id, Using = "Test"
            };
            FindsByAttribute second = new FindsByAttribute()
            {
                How = How.Id, Using = "Test"
            };

            Assert.IsTrue(first.Equals(second));
            Assert.IsFalse(object.ReferenceEquals(first, second));
            Assert.IsTrue(first == second);
            Assert.IsFalse(first != second);
        }
예제 #26
0
        public void TestInequalityOfNull()
        {
            FindsByAttribute first = new FindsByAttribute()
            {
                How = How.Id, Using = "Test"
            };
            FindsByAttribute second = null;

            Assert.IsFalse(first.Equals(second));

            // Must test order of arguments for overridden operators
            Assert.IsFalse(first == second);
            Assert.IsTrue(first != second);
            Assert.IsFalse(second == first);
            Assert.IsTrue(second != first);
        }
예제 #27
0
        /// <summary>
        /// Gets an instance of the <see cref="By"/> class based on the specified attribute.
        /// </summary>
        /// <param name="attribute">The <see cref="FindsByAttribute"/> describing how to find the element.</param>
        /// <returns>An instance of the <see cref="By"/> class.</returns>
        public static By From(FindsByAttribute attribute)
        {
            var how = attribute.How;
            var usingValue = attribute.Using;
            switch (how)
            {
                case How.Id:
                    return By.Id(usingValue);
                case How.Name:
                    return By.Name(usingValue);
                case How.TagName:
                    return By.TagName(usingValue);
                case How.ClassName:
                    return By.ClassName(usingValue);
                case How.CssSelector:
                    return By.CssSelector(usingValue);
                case How.LinkText:
                    return By.LinkText(usingValue);
                case How.PartialLinkText:
                    return By.PartialLinkText(usingValue);
                case How.XPath:
                    return By.XPath(usingValue);
                case How.Custom:
                    if (attribute.CustomFinderType == null)
                    {
                        throw new ArgumentException("Cannot use How.Custom without supplying a custom finder type");
                    }

                    if (!attribute.CustomFinderType.IsSubclassOf(typeof(By)))
                    {
                        throw new ArgumentException("Custom finder type must be a descendent of the By class");
                    }

                    ConstructorInfo ctor = attribute.CustomFinderType.GetConstructor(new Type[] { typeof(string) });
                    if (ctor == null)
                    {
                        throw new ArgumentException("Custom finder type must expose a public constructor with a string argument");
                    }

                    By finder = ctor.Invoke(new object[] { usingValue }) as By;
                    return finder;
            }

            throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Did not know how to construct How from how {0}, using {1}", how, usingValue));
        }
예제 #28
0
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj", "Object to compare cannot be null");
            }
            FindsByAttribute findsByAttribute = obj as FindsByAttribute;

            if (findsByAttribute == null)
            {
                throw new ArgumentException("Object to compare must be a FindsByAttribute", "obj");
            }
            if (this.Priority != findsByAttribute.Priority)
            {
                return(this.Priority - findsByAttribute.Priority);
            }
            return(0);
        }
예제 #29
0
        public void TestEqualityOfFinder()
        {
            By findBy = By.Id("Test");
            FindsByAttribute first = new FindsByAttribute() { Finder = findBy };

            // Use different instance of By class.
            FindsByAttribute second = new FindsByAttribute() { Finder = By.Id("Test") };
            Assert.IsTrue(first == second);
            Assert.IsTrue(second == first);
            Assert.IsFalse(first != second);
            Assert.IsFalse(second != first);
            Assert.IsTrue(first.Equals(second));

            // Use same instance of By class.
            second.Finder = findBy;
            Assert.IsTrue(first == second);
            Assert.IsTrue(second == first);
            Assert.IsFalse(first != second);
            Assert.IsFalse(second != first);
            Assert.IsTrue(first.Equals(second));
        }
예제 #30
0
        private void AssertValidFindBy(FindsByAttribute findBy)
        {
            if (findBy.How == How.Custom)
            {
                if (findBy.CustomFinderType == null)
                {
                    throw new ArgumentException(
                            "If you set the 'How' property to 'Custom' value, you must also set 'CustomFinderType'");
                }
                if (!findBy.CustomFinderType.IsSubclassOf(typeof(By)))
                {
                    throw new ArgumentException("Custom finder type must be a descendent of the 'By' class");
                }

                ConstructorInfo ctor = findBy.CustomFinderType.GetConstructor(new Type[] { typeof(string) });
                if (ctor == null)
                {
                    throw new ArgumentException("Custom finder type must expose a public constructor with a string argument");
                }
            }
        }
예제 #31
0
        /// <summary>
        /// Compares the current instance with another object of the same type and returns an
        /// integer that indicates whether the current instance precedes, follows, or occurs
        /// in the same position in the sort order as the other object.
        /// </summary>
        /// <param name="obj">An object to compare with this instance.</param>
        /// <returns>A value that indicates the relative order of the objects being compared. The return value has these meanings:
        /// <list type="table">
        /// <listheader>Value</listheader><listheader>Meaning</listheader>
        /// <item><description>Less than zero</description><description>This instance precedes <paramref name="obj"/> in the sort order.</description></item>
        /// <item><description>Zero</description><description>This instance occurs in the same position in the sort order as <paramref name="obj"/>.</description></item>
        /// <item><description>Greater than zero</description><description>This instance follows <paramref name="obj"/> in the sort order. </description></item>
        /// </list>
        /// </returns>
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj", "Object to compare cannot be null");
            }

            FindsByAttribute other = obj as FindsByAttribute;

            if (other == null)
            {
                throw new ArgumentException("Object to compare must be a FindsByAttribute", "obj");
            }

            // TODO(JimEvans): Construct an algorithm to sort on more than just Priority.
            if (this.Priority != other.Priority)
            {
                return(this.Priority - other.Priority);
            }

            return(0);
        }
예제 #32
0
 public static By GetLocatorFromFindBy(FindsByAttribute fbAttr)
 {
     switch (fbAttr.How)
     {
         case How.Id:
             return By.Id(fbAttr.Using);
         case How.Name:
             return By.Name(fbAttr.Using);
         case How.ClassName:
             return By.ClassName(fbAttr.Using);
         case How.CssSelector:
             return By.CssSelector(fbAttr.Using);
         case How.XPath:
             return By.XPath(fbAttr.Using);
         case How.TagName:
             return By.TagName(fbAttr.Using);
         case How.LinkText:
             return By.LinkText(fbAttr.Using);
         case How.PartialLinkText:
             return By.PartialLinkText(fbAttr.Using);
         default:
             return By.Id("Undefined locator");
     }
 }
        public void TestLocatorCreatePartialLinkText()
        {
            var attribute = new FindsByAttribute { How = How.PartialLinkText, Using = "Hello" };

            var locator = NativeAttributeBuilder.GetLocator(attribute);

            Assert.AreEqual(By.PartialLinkText("Hello"), locator);
        }
        public void TestLocatorCreateXPath()
        {
            var attribute = new FindsByAttribute { How = How.XPath, Using = "//tag" };

            var locator = NativeAttributeBuilder.GetLocator(attribute);

            Assert.AreEqual(By.XPath("//tag"), locator);
        }
 public static By Create(FindsByAttribute attribute) {
     return Create(attribute.How, attribute.Using, attribute.CustomFinderType);
 }
예제 #36
0
 public void TestInqualityOfFinder()
 {
     FindsByAttribute first = new FindsByAttribute() { Finder = By.Id("Test") };
     FindsByAttribute second = new FindsByAttribute() { Finder = By.Name("Test") };
     Assert.IsFalse(first == second);
     Assert.IsFalse(second == first);
     Assert.IsFalse(first.Equals(second));
 }
예제 #37
0
 protected virtual By BuildByFromFindsBy(FindsByAttribute findsBy)
 {
     AssertValidFindBy(findsBy);
     return BuildBy(findsBy);
 }
예제 #38
0
 private void AssertValidFindBys(FindsByAttribute[] findBys)
 {
     foreach (FindsByAttribute findBy in findBys)
     {
         AssertValidFindBy(findBy);
     }
 }
        public void TestCustomClass()
        {
            var attribute = new FindsByAttribute { How = How.Custom, Using = "notsupported" };

            var locator = NativeAttributeBuilder.GetLocator(attribute);

            Assert.AreEqual(null, locator);
        }