コード例 #1
0
        public void FindElementTwoByEmptyChild()
        {
            Mock <IAllDriver> driver = new Mock <IAllDriver>();

            Mock <IAllElement> elem1 = new Mock <IAllElement>();
            Mock <IAllElement> elem2 = new Mock <IAllElement>();
            Mock <IAllElement> elem5 = new Mock <IAllElement>();

            var elems   = new List <IWebElement>().AsReadOnly();
            var elems12 = new List <IWebElement>()
            {
                elem1.Object, elem2.Object
            }.AsReadOnly();
            var elems5 = new List <IWebElement>()
            {
                elem5.Object
            }.AsReadOnly();

            driver.Setup(_ => _.FindElementsByName(It.Is <string>(x => x == "cheese"))).Returns(elems12);
            elem1.Setup(_ => _.FindElements(It.Is <By>(x => x.Equals(By.Name("photo"))))).Returns(elems);
            elem2.Setup(_ => _.FindElements(It.Is <By>(x => x.Equals(By.Name("photo"))))).Returns(elems5);

            ByChained by = new ByChained(By.Name("cheese"), By.Name("photo"));

            Assert.That(by.FindElement(driver.Object), Is.EqualTo(elem5.Object));
            driver.Verify(_ => _.FindElementsByName("cheese"), Times.Once);
            elem1.Verify(_ => _.FindElements(By.Name("photo")), Times.Once);
            elem2.Verify(_ => _.FindElements(By.Name("photo")), Times.Once);
        }
コード例 #2
0
        public void FindElementTwoByEmptyChild()
        {
            MockFactory       mocks  = new MockFactory();
            Mock <IAllDriver> driver = mocks.CreateMock <IAllDriver>();

            Mock <IAllElement> elem1 = mocks.CreateMock <IAllElement>();
            Mock <IAllElement> elem2 = mocks.CreateMock <IAllElement>();
            Mock <IAllElement> elem5 = mocks.CreateMock <IAllElement>();

            var elems   = new List <IWebElement>().AsReadOnly();
            var elems12 = new List <IWebElement>()
            {
                elem1.MockObject, elem2.MockObject
            }.AsReadOnly();
            var elems5 = new List <IWebElement>()
            {
                elem5.MockObject
            }.AsReadOnly();

            driver.Expects.One.Method(_ => _.FindElementsByName(null)).With("cheese").WillReturn(elems12);
            elem1.Expects.One.Method(_ => _.FindElements(null)).With(By.Name("photo")).WillReturn(elems);
            elem2.Expects.One.Method(_ => _.FindElements(null)).With(By.Name("photo")).WillReturn(elems5);

            ByChained by = new ByChained(By.Name("cheese"), By.Name("photo"));

            Assert.That(by.FindElement(driver.MockObject), Is.EqualTo(elem5.MockObject));
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
コード例 #3
0
ファイル: PageFactory.cs プロジェクト: anthrax3/selenium-3
        private static List <By> CreateLocatorList(MemberInfo member)
        {
            var  useSequenceAttributes = Attribute.GetCustomAttributes(member, typeof(FindsBySequenceAttribute), true);
            bool useSequence           = useSequenceAttributes.Length > 0;

            List <By> bys        = new List <By>();
            var       attributes = Attribute.GetCustomAttributes(member, typeof(FindsByAttribute), true);

            if (attributes.Length > 0)
            {
                Array.Sort(attributes);
                foreach (var attribute in attributes)
                {
                    var castedAttribute = (FindsByAttribute)attribute;
                    if (castedAttribute.Using == null)
                    {
                        castedAttribute.Using = member.Name;
                    }

                    bys.Add(castedAttribute.Finder);
                }

                if (useSequence)
                {
                    ByChained chained = new ByChained(bys.ToArray());
                    bys.Clear();
                    bys.Add(chained);
                }
            }

            return(bys);
        }
コード例 #4
0
        public void FindElementTwoByEmptyChild()
        {
            Mockery    mocks  = new Mockery();
            IAllDriver driver = mocks.NewMock <IAllDriver>();

            IAllElement elem1   = mocks.NewMock <IAllElement>();
            IAllElement elem2   = mocks.NewMock <IAllElement>();
            IAllElement elem5   = mocks.NewMock <IAllElement>();
            var         elems   = new List <IWebElement>().AsReadOnly();
            var         elems12 = new List <IWebElement>()
            {
                elem1, elem2
            }.AsReadOnly();
            var elems5 = new List <IWebElement>()
            {
                elem5
            }.AsReadOnly();

            Expect.Once.On(driver).Method("FindElementsByName").With("cheese").Will(Return.Value(elems12));
            Expect.Once.On(elem1).Method("FindElements").With(By.Name("photo")).Will(Return.Value(elems));
            Expect.Once.On(elem2).Method("FindElements").With(By.Name("photo")).Will(Return.Value(elems5));

            ByChained by = new ByChained(By.Name("cheese"), By.Name("photo"));

            Assert.That(by.FindElement(driver), Is.EqualTo(elem5));
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
コード例 #5
0
        public void FindElementsZeroBy()
        {
            Mock <IAllDriver> driver = new Mock <IAllDriver>();

            ByChained by = new ByChained();

            Assert.That(by.FindElements(driver.Object), Is.EqualTo(new List <IWebElement>().AsReadOnly()));
        }
コード例 #6
0
        public void FindElementZeroBy()
        {
            Mock <IAllDriver> driver = new Mock <IAllDriver>();

            ByChained by = new ByChained();

            Assert.Throws <NoSuchElementException>(() => by.FindElement(driver.Object));
        }
コード例 #7
0
ファイル: ByChainedTests.cs プロジェクト: kaushik9k/Selenium2
        public void FindElementZeroBy()
        {
            Mockery mock = new Mockery();
            IAllDriver driver = mock.NewMock<IAllDriver>();

            ByChained by = new ByChained();
            by.FindElement(driver);
        }
コード例 #8
0
        public void FindElement_ShouldReturnOne()
        {
            driver.Url = nestedPage;
            driver.Navigate();

            var by = new ByChained(By.Name("div1"));
            Assert.IsTrue(by.FindElement(driver).Displayed);
        }
コード例 #9
0
ファイル: ByChainedTests.cs プロジェクト: RanchoLi/selenium
        public void FindElementZeroBy()
        {
            Mockery mock = new Mockery();
            IAllDriver driver = mock.NewMock<IAllDriver>();

            ByChained by = new ByChained();
            Assert.Throws<NoSuchElementException>(() => by.FindElement(driver));
        }
コード例 #10
0
        public void FindElements_ShouldReturnMultiple()
        {
            driver.Url = nestedPage;
            driver.Navigate();

            var by = new ByChained(By.Name("div1"));
            Assert.AreEqual(4, by.FindElements(driver).Count);
        }
コード例 #11
0
        public void FindElement_TwoBys_ShouldReturnOne()
        {
            driver.Url = nestedPage;
            driver.Navigate();

            var by = new ByChained(By.Name("classes"), By.CssSelector(".one"));
            Assert.AreEqual("Find me", by.FindElement(driver).Text);
        }
コード例 #12
0
        public void FindElements_ShouldReturnMultiple()
        {
            driver.Url = nestedPage;
            driver.Navigate();

            var by = new ByChained(By.Name("div1"));

            Assert.AreEqual(4, by.FindElements(driver).Count);
        }
コード例 #13
0
ファイル: ByChainedTests.cs プロジェクト: kaushik9k/Selenium2
        public void FindElementsZeroBy()
        {
            Mockery mock = new Mockery();
            IAllDriver driver = mock.NewMock<IAllDriver>();

            ByChained by = new ByChained();

            Assert.That(by.FindElements(driver), Is.EqualTo(new List<IWebElement>().AsReadOnly()));
        }
コード例 #14
0
        public void FindElement_TwoBys_ShouldReturnOne()
        {
            driver.Url = nestedPage;
            driver.Navigate();

            var by = new ByChained(By.Name("classes"), By.CssSelector(".one"));

            Assert.AreEqual("Find me", by.FindElement(driver).Text);
        }
コード例 #15
0
        public void FindElements_TwoBys_ShouldReturnZero()
        {
            driver.Url = nestedPage;
            driver.Navigate();

            var by = new ByChained(By.Name("classes"), By.CssSelector(".NotFound"));

            Assert.AreEqual(0, by.FindElements(driver).Count);
        }
コード例 #16
0
        public void FindElementsNotFound_ShouldBeZero()
        {
            driver.Url = nestedPage;
            driver.Navigate();

            var by = new ByChained(By.Name("NotFoundAtAll"));
                
            Assert.AreEqual(0, by.FindElements(driver).Count);
        }
コード例 #17
0
        public void FindElementsNotFound_ShouldBeZero()
        {
            driver.Url = nestedPage;
            driver.Navigate();

            var by = new ByChained(By.Name("NotFoundAtAll"));

            Assert.AreEqual(0, by.FindElements(driver).Count);
        }
コード例 #18
0
        public void FindElementZeroBy()
        {
            Mockery    mock   = new Mockery();
            IAllDriver driver = mock.NewMock <IAllDriver>();

            ByChained by = new ByChained();

            Assert.Throws <NoSuchElementException>(() => by.FindElement(driver));
        }
コード例 #19
0
        public void FindElementZeroBy()
        {
            Mockery    mock   = new Mockery();
            IAllDriver driver = mock.NewMock <IAllDriver>();

            ByChained by = new ByChained();

            by.FindElement(driver);
        }
コード例 #20
0
        public void FindElementZeroBy()
        {
            MockFactory       mock   = new MockFactory();
            Mock <IAllDriver> driver = mock.CreateMock <IAllDriver>();

            ByChained by = new ByChained();

            Assert.Throws <NoSuchElementException>(() => by.FindElement(driver.MockObject));
        }
コード例 #21
0
        public void FindElement_ShouldReturnOne()
        {
            driver.Url = nestedPage;
            driver.Navigate();

            var by = new ByChained(By.Name("div1"));

            Assert.IsTrue(by.FindElement(driver).Displayed);
        }
コード例 #22
0
        public void FindElementsOneByEmpty()
        {
            Mock <IAllDriver> driver = new Mock <IAllDriver>();
            var elems = new List <IWebElement>().AsReadOnly();

            driver.Setup(_ => _.FindElementsByName(It.Is <string>(x => x == "cheese"))).Returns(elems);

            ByChained by = new ByChained(By.Name("cheese"));

            Assert.That(by.FindElements(driver.Object), Is.EqualTo(elems));
        }
コード例 #23
0
        public void FindElementsOneByEmpty()
        {
            Mockery    mock   = new Mockery();
            IAllDriver driver = mock.NewMock <IAllDriver>();
            var        elems  = new List <IWebElement>().AsReadOnly();

            Expect.Once.On(driver).Method("FindElementsByName").With("cheese").Will(Return.Value(elems));

            ByChained by = new ByChained(By.Name("cheese"));

            Assert.That(by.FindElements(driver), Is.EqualTo(elems));
        }
コード例 #24
0
ファイル: ByChainedTests.cs プロジェクト: Zekom/selenium
        public void FindElementsOneByEmpty()
        {
            Mockery mock = new Mockery();
            IAllDriver driver = mock.NewMock<IAllDriver>();
            var elems = new List<IWebElement>().AsReadOnly();

            Expect.Once.On(driver).Method("FindElementsByName").With("cheese").Will(Return.Value(elems));

            ByChained by = new ByChained(By.Name("cheese"));

            Assert.That(by.FindElements(driver), Is.EqualTo(elems));
        }
コード例 #25
0
        public void FindElementsOneByEmpty()
        {
            MockFactory       mock   = new MockFactory();
            Mock <IAllDriver> driver = mock.CreateMock <IAllDriver>();
            var elems = new List <IWebElement>().AsReadOnly();

            driver.Expects.One.Method(_ => _.FindElementsByName(null)).With("cheese").WillReturn(elems);

            ByChained by = new ByChained(By.Name("cheese"));

            Assert.That(by.FindElements(driver.MockObject), Is.EqualTo(elems));
        }
コード例 #26
0
        /// <summary>
        /// Creates a list of <see cref="By"/> locators based on the attributes of this member.
        /// </summary>
        /// <param name="member">The <see cref="MemberInfo"/> containing information about
        /// the member of the Page Object class.</param>
        /// <returns>A list of <see cref="By"/> locators based on the attributes of this member.</returns>
        protected static ReadOnlyCollection <By> CreateLocatorList(MemberInfo member)
        {
            if (member == null)
            {
                throw new ArgumentNullException("member", "memeber cannot be null");
            }

            var  useSequenceAttributes = Attribute.GetCustomAttributes(member, typeof(FindsBySequenceAttribute), true);
            bool useSequence           = useSequenceAttributes.Length > 0;

            var  useFindAllAttributes = Attribute.GetCustomAttributes(member, typeof(FindsByAllAttribute), true);
            bool useAll = useFindAllAttributes.Length > 0;

            if (useSequence && useAll)
            {
                throw new ArgumentException("Cannot specify FindsBySequence and FindsByAll on the same member");
            }

            List <By> bys        = new List <By>();
            var       attributes = Attribute.GetCustomAttributes(member, typeof(FindsByAttribute), true);

            if (attributes.Length > 0)
            {
                Array.Sort(attributes);
                foreach (var attribute in attributes)
                {
                    var castedAttribute = (FindsByAttribute)attribute;
                    if (castedAttribute.Using == null)
                    {
                        castedAttribute.Using = member.Name;
                    }

                    bys.Add(castedAttribute.Finder);
                }

                if (useSequence)
                {
                    ByChained chained = new ByChained(bys.ToArray());
                    bys.Clear();
                    bys.Add(chained);
                }

                if (useAll)
                {
                    ByAll all = new ByAll(bys.ToArray());
                    bys.Clear();
                    bys.Add(all);
                }
            }

            return(bys.AsReadOnly());
        }
コード例 #27
0
ファイル: ByChainedTests.cs プロジェクト: kaushik9k/Selenium2
        public void FindElementsOneBy()
        {
            Mockery mock = new Mockery();
            IAllDriver driver = mock.NewMock<IAllDriver>();
            IAllElement elem1 = mock.NewMock<IAllElement>();
            IAllElement elem2 = mock.NewMock<IAllElement>();
            var elems12 = new List<IWebElement>() { elem1, elem2 }.AsReadOnly();
            Expect.Once.On(driver).Method("FindElementsByName").With("cheese").Will(Return.Value(elems12));

            ByChained by = new ByChained(By.Name("cheese"));
            Assert.AreEqual(by.FindElements(driver), elems12);
            mock.VerifyAllExpectationsHaveBeenMet();
        }
コード例 #28
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());
        }
コード例 #29
0
        public void FindElement_TwoBys_ShouldThrow()
        {
            driver.Url = nestedPage;
            driver.Navigate();

            try
            {
                var by = new ByChained(By.Name("classes"), By.CssSelector(".NotFound"));
                by.FindElement(driver);
                Assert.Fail("Expected NotFoundException");
            }
            catch (NotFoundException)
            {
                Assert.Pass();
            }
        }
コード例 #30
0
        public void FindElementNotFound_ShouldThrow()
        {
            driver.Url = nestedPage;
            driver.Navigate();

            var by = new ByChained(By.Name("NotFoundAtAll"));
            try
            {
                by.FindElement(driver);
                Assert.Fail("Expected NotFoundExcepotion");
            }
            catch (NotFoundException)
            {
                Assert.Pass();
            }
        }
コード例 #31
0
        public void FindElementsOneBy()
        {
            Mock <IAllDriver>  driver = new Mock <IAllDriver>();
            Mock <IAllElement> elem1  = new Mock <IAllElement>();
            Mock <IAllElement> elem2  = new Mock <IAllElement>();
            var elems12 = new List <IWebElement>()
            {
                elem1.Object, elem2.Object
            }.AsReadOnly();

            driver.Setup(_ => _.FindElementsByName(It.Is <string>(x => x == "cheese"))).Returns(elems12);

            ByChained by = new ByChained(By.Name("cheese"));

            Assert.AreEqual(by.FindElements(driver.Object), elems12);
            driver.Verify(_ => _.FindElementsByName("cheese"), Times.Once);
        }
コード例 #32
0
        public void FindElementNotFound_ShouldThrow()
        {
            driver.Url = nestedPage;
            driver.Navigate();

            var by = new ByChained(By.Name("NotFoundAtAll"));

            try
            {
                by.FindElement(driver);
                Assert.Fail("Expected NotFoundExcepotion");
            }
            catch (NotFoundException)
            {
                Assert.Pass();
            }
        }
コード例 #33
0
        public void FindElementsOneBy()
        {
            Mockery     mock    = new Mockery();
            IAllDriver  driver  = mock.NewMock <IAllDriver>();
            IAllElement elem1   = mock.NewMock <IAllElement>();
            IAllElement elem2   = mock.NewMock <IAllElement>();
            var         elems12 = new List <IWebElement>()
            {
                elem1, elem2
            }.AsReadOnly();

            Expect.Once.On(driver).Method("FindElementsByName").With("cheese").Will(Return.Value(elems12));

            ByChained by = new ByChained(By.Name("cheese"));

            Assert.AreEqual(by.FindElements(driver), elems12);
            mock.VerifyAllExpectationsHaveBeenMet();
        }
コード例 #34
0
        private static List<By> GetListOfComplexBys(bool useSequence, bool useAll, List<By> bys)
        {
            if (useSequence)
            {
                ByChained chained = new ByChained(bys.ToArray());
                bys.Clear();
                bys.Add(chained);
            }

            if (useAll)
            {
                ByAll all = new ByAll(bys.ToArray());
                bys.Clear();
                bys.Add(all);
            }

            return bys;
        }
コード例 #35
0
        public void FindElementsOneBy()
        {
            MockFactory        mock   = new MockFactory();
            Mock <IAllDriver>  driver = mock.CreateMock <IAllDriver>();
            Mock <IAllElement> elem1  = mock.CreateMock <IAllElement>();
            Mock <IAllElement> elem2  = mock.CreateMock <IAllElement>();
            var elems12 = new List <IWebElement>()
            {
                elem1.MockObject, elem2.MockObject
            }.AsReadOnly();

            driver.Expects.One.Method(_ => _.FindElementsByName(null)).With("cheese").WillReturn(elems12);

            ByChained by = new ByChained(By.Name("cheese"));

            Assert.AreEqual(by.FindElements(driver.MockObject), elems12);
            mock.VerifyAllExpectationsHaveBeenMet();
        }
コード例 #36
0
ファイル: ByChainedTests.cs プロジェクト: kaushik9k/Selenium2
        public void FindElementOneByEmpty()
        {
            Mockery mock = new Mockery();
            IAllDriver driver = mock.NewMock<IAllDriver>();
            var elems = new List<IWebElement>().AsReadOnly();

            Expect.Once.On(driver).Method("FindElementsByName").With("cheese").Will(Return.Value(elems));

            ByChained by = new ByChained(By.Name("cheese"));
            try
            {
                by.FindElement(driver);
                Assert.Fail("Expected NoSuchElementException!");
            }
            catch (NoSuchElementException)
            {
                mock.VerifyAllExpectationsHaveBeenMet();
                Assert.Pass();
            }
        }
コード例 #37
0
        public void FindElementOneByEmpty()
        {
            Mock <IAllDriver> driver = new Mock <IAllDriver>();
            var elems = new List <IWebElement>().AsReadOnly();

            driver.Setup(_ => _.FindElementsByName(It.Is <string>(x => x == "cheese"))).Returns(elems);

            ByChained by = new ByChained(By.Name("cheese"));

            try
            {
                by.FindElement(driver.Object);
                Assert.Fail("Expected NoSuchElementException!");
            }
            catch (NoSuchElementException)
            {
                driver.Verify(_ => _.FindElementsByName("cheese"), Times.Once);
                Assert.Pass();
            }
        }
コード例 #38
0
        public void FindElementOneByEmpty()
        {
            MockFactory       mock   = new MockFactory();
            Mock <IAllDriver> driver = mock.CreateMock <IAllDriver>();
            var elems = new List <IWebElement>().AsReadOnly();

            driver.Expects.One.Method(_ => _.FindElementsByName(null)).With("cheese").WillReturn(elems);

            ByChained by = new ByChained(By.Name("cheese"));

            try
            {
                by.FindElement(driver.MockObject);
                Assert.Fail("Expected NoSuchElementException!");
            }
            catch (NoSuchElementException)
            {
                mock.VerifyAllExpectationsHaveBeenMet();
                Assert.Pass();
            }
        }
コード例 #39
0
        public void FindElementOneByEmpty()
        {
            Mockery    mock   = new Mockery();
            IAllDriver driver = mock.NewMock <IAllDriver>();
            var        elems  = new List <IWebElement>().AsReadOnly();

            Expect.Once.On(driver).Method("FindElementsByName").With("cheese").Will(Return.Value(elems));

            ByChained by = new ByChained(By.Name("cheese"));

            try
            {
                by.FindElement(driver);
                Assert.Fail("Expected NoSuchElementException!");
            }
            catch (NoSuchElementException)
            {
                mock.VerifyAllExpectationsHaveBeenMet();
                Assert.Pass();
            }
        }
コード例 #40
0
ファイル: ByChainedTests.cs プロジェクト: kaushik9k/Selenium2
        public void FindElementsTwoByEmptyChild()
        {
            Mockery mocks = new Mockery();
            IAllDriver driver = mocks.NewMock<IAllDriver>();

            IAllElement elem1 = mocks.NewMock<IAllElement>();
            IAllElement elem2 = mocks.NewMock<IAllElement>();
            IAllElement elem3 = mocks.NewMock<IAllElement>();
            IAllElement elem4 = mocks.NewMock<IAllElement>();
            IAllElement elem5 = mocks.NewMock<IAllElement>();
            var elems = new List<IWebElement>().AsReadOnly();
            var elems12 = new List<IWebElement>() { elem1, elem2 }.AsReadOnly();
            var elems34 = new List<IWebElement>() { elem3, elem4 }.AsReadOnly();
            var elems5 = new List<IWebElement>() { elem5 }.AsReadOnly();
            var elems345 = new List<IWebElement>() { elem3, elem4, elem5 }.AsReadOnly();

            Expect.Once.On(driver).Method("FindElementsByName").With("cheese").Will(Return.Value(elems12));
            Expect.Once.On(elem1).Method("FindElements").With(By.Name("photo")).Will(Return.Value(elems));
            Expect.Once.On(elem2).Method("FindElements").With(By.Name("photo")).Will(Return.Value(elems5));

            ByChained by = new ByChained(By.Name("cheese"), By.Name("photo"));
            Assert.That(by.FindElements(driver), Is.EqualTo(new[] { elem5 }));
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
コード例 #41
0
        /// <summary>
        /// Creates a list of <see cref="By"/> locators based on the attributes of this member.
        /// </summary>
        /// <param name="member">The <see cref="MemberInfo"/> containing information about
        /// the member of the Page Object class.</param>
        /// <returns>A list of <see cref="By"/> locators based on the attributes of this member.</returns>
        protected static ReadOnlyCollection<By> CreateLocatorList(MemberInfo member)
        {
            if (member == null)
            {
                throw new ArgumentNullException("member", "memeber cannot be null");
            }

            var useSequenceAttributes = Attribute.GetCustomAttributes(member, typeof(FindsBySequenceAttribute), true);
            bool useSequence = useSequenceAttributes.Length > 0;

            var useFindAllAttributes = Attribute.GetCustomAttributes(member, typeof(FindsByAllAttribute), true);
            bool useAll = useFindAllAttributes.Length > 0;

            if (useSequence && useAll)
            {
                throw new ArgumentException("Cannot specify FindsBySequence and FindsByAll on the same member");
            }

            List<By> bys = new List<By>();
            var attributes = Attribute.GetCustomAttributes(member, typeof(FindsByAttribute), true);
            if (attributes.Length > 0)
            {
                Array.Sort(attributes);
                foreach (var attribute in attributes)
                {
                    var castedAttribute = (FindsByAttribute)attribute;
                    if (castedAttribute.Using == null)
                    {
                        castedAttribute.Using = member.Name;
                    }

                    bys.Add(castedAttribute.Finder);
                }

                if (useSequence)
                {
                    ByChained chained = new ByChained(bys.ToArray());
                    bys.Clear();
                    bys.Add(chained);
                }

                if (useAll)
                {
                    ByAll all = new ByAll(bys.ToArray());
                    bys.Clear();
                    bys.Add(all);
                }
            }

            return bys.AsReadOnly();
        }
コード例 #42
0
        public void FindElements_TwoBys_ShouldReturnZero()
        {
            driver.Url = nestedPage;
            driver.Navigate();

            var by = new ByChained(By.Name("classes"), By.CssSelector(".NotFound"));
            Assert.AreEqual(0, by.FindElements(driver).Count);
        }
コード例 #43
0
ファイル: ByChainedTests.cs プロジェクト: kaushik9k/Selenium2
        public void FindElementsTwoByEmptyParent()
        {
            Mockery mocks = new Mockery();
            IAllDriver driver = mocks.NewMock<IAllDriver>();

            var elems = new List<IWebElement>().AsReadOnly();

            Expect.Once.On(driver).Method("FindElementsByName").With("cheese").Will(Return.Value(elems));

            ByChained by = new ByChained(By.Name("cheese"), By.Name("photo"));

            Assert.That(by.FindElements(driver), Is.EqualTo(elems));
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
コード例 #44
0
        public void FindElement_TwoBys_ShouldThrow()
        {
            driver.Url = nestedPage;
            driver.Navigate();

            try
            {
                var by = new ByChained(By.Name("classes"), By.CssSelector(".NotFound"));
                by.FindElement(driver);
                Assert.Fail("Expected NotFoundException");
            }
            catch (NotFoundException) 
            {
                Assert.Pass();
            }
        }