Пример #1
0
        public void FindElementDisjunct()
        {
            var driver = new Mock <IAllDriver>();

            var elem1 = new Mock <IAllElement>();
            var elem2 = new Mock <IAllElement>();
            var elem3 = new Mock <IAllElement>();
            var elem4 = new Mock <IAllElement>();
            var elems12 = new List <IWebElement> {
                elem1.Object, elem2.Object
            }.AsReadOnly();
            var elems34 = new List <IWebElement> {
                elem3.Object, elem4.Object
            }.AsReadOnly();

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

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

            Assert.Throws <NoSuchElementException>(() => by.FindElement(driver.Object));

            var result = by.FindElements(driver.Object);

            Assert.That(result.Count, Is.EqualTo(0));
            driver.Verify(_ => _.FindElementsByName("cheese"), Times.AtLeastOnce);
            driver.Verify(_ => _.FindElementsByName("photo"), Times.AtLeastOnce);
        }
Пример #2
0
        public void FindElementDisjunct()
        {
            var mocks  = new MockFactory();
            var driver = mocks.CreateMock <IAllDriver>();

            var elem1 = mocks.CreateMock <IAllElement>();
            var elem2 = mocks.CreateMock <IAllElement>();
            var elem3 = mocks.CreateMock <IAllElement>();
            var elem4 = mocks.CreateMock <IAllElement>();
            var elems12 = new List <IWebElement> {
                elem1.MockObject, elem2.MockObject
            }.AsReadOnly();
            var elems34 = new List <IWebElement> {
                elem3.MockObject, elem4.MockObject
            }.AsReadOnly();

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

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

            Assert.Throws <NoSuchElementException>(() => by.FindElement(driver.MockObject));

            var result = by.FindElements(driver.MockObject);

            Assert.That(result.Count, Is.EqualTo(0));
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Пример #3
0
        public void FindElementTwoBy()
        {
            var mocks  = new Mockery();
            var driver = mocks.NewMock <IAllDriver>();

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

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

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

            // findElement
            Assert.That(by.FindElement(driver), Is.EqualTo(elem2));

            //findElements
            var result = by.FindElements(driver);

            Assert.That(result.Count, Is.EqualTo(1));
            Assert.That(result[0], Is.EqualTo(elem2));

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Пример #4
0
        public void FindElementTwoBy()
        {
            var driver = new Mock <IAllDriver>();

            var elem1 = new Mock <IAllElement>();
            var elem2 = new Mock <IAllElement>();
            var elem3 = new Mock <IAllElement>();
            var elems12 = new List <IWebElement> {
                elem1.Object, elem2.Object
            }.AsReadOnly();
            var elems23 = new List <IWebElement> {
                elem2.Object, elem3.Object
            }.AsReadOnly();

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

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

            // findElement
            Assert.That(by.FindElement(driver.Object), Is.EqualTo(elem2.Object));

            //findElements
            var result = by.FindElements(driver.Object);

            Assert.That(result.Count, Is.EqualTo(1));
            Assert.That(result[0], Is.EqualTo(elem2.Object));

            driver.Verify(_ => _.FindElementsByName("cheese"), Times.AtLeastOnce);
            driver.Verify(_ => _.FindElementsByName("photo"), Times.AtLeastOnce);
        }
Пример #5
0
        public void FindElementDisjunct()
        {
            var mocks  = new Mockery();
            var driver = mocks.NewMock <IAllDriver>();

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

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

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

            Assert.Throws <NoSuchElementException>(() => by.FindElement(driver));

            var result = by.FindElements(driver);

            Assert.That(result.Count, Is.EqualTo(0));
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Пример #6
0
        public void FindElementTwoBy()
        {
            var mocks  = new MockFactory();
            var driver = mocks.CreateMock <IAllDriver>();

            var elem1 = mocks.CreateMock <IAllElement>();
            var elem2 = mocks.CreateMock <IAllElement>();
            var elem3 = mocks.CreateMock <IAllElement>();
            var elems12 = new List <IWebElement> {
                elem1.MockObject, elem2.MockObject
            }.AsReadOnly();
            var elems23 = new List <IWebElement> {
                elem2.MockObject, elem3.MockObject
            }.AsReadOnly();

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

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

            // findElement
            Assert.That(by.FindElement(driver.MockObject), Is.EqualTo(elem2.MockObject));

            //findElements
            var result = by.FindElements(driver.MockObject);

            Assert.That(result.Count, Is.EqualTo(1));
            Assert.That(result[0], Is.EqualTo(elem2.MockObject));

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Пример #7
0
        public void FindElementZeroBy()
        {
            var driver = new Mock <IAllDriver>();

            var by = new ByAll();

            Assert.Throws <NoSuchElementException>(() => by.FindElement(driver.Object));
            Assert.That(by.FindElements(driver.Object), Is.EqualTo(new List <IWebElement>().AsReadOnly()));
        }
Пример #8
0
        public void FindElementZeroBy()
        {
            var mock = new Mockery();
            var driver = mock.NewMock<IAllDriver>();

            var by = new ByAll();

            Assert.Throws<NoSuchElementException>(() => by.FindElement(driver));
            Assert.That(by.FindElements(driver), Is.EqualTo(new List<IWebElement>().AsReadOnly()));
        }
        /// <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());
        }
Пример #10
0
        public void FindElementOneByEmpty()
        {
            var driver = new Mock <IAllDriver>();
            var empty  = new List <IWebElement>().AsReadOnly();

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

            var by = new ByAll(By.Name("cheese"));

            // one element
            Assert.Throws <NoSuchElementException>(() => by.FindElement(driver.Object));
            Assert.That(by.FindElements(driver.Object), Is.EqualTo(empty));

            driver.Verify(_ => _.FindElementsByName("cheese"), Times.AtLeastOnce);
        }
Пример #11
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());
        }
Пример #12
0
        public void FindElementOneByEmpty()
        {
            var mock = new Mockery();
            var driver = mock.NewMock<IAllDriver>();
            var empty = new List<IWebElement>().AsReadOnly();

            Expect.AtLeastOnce.On(driver).Method("FindElementsByName").With("cheese").Will(Return.Value(empty));

            var by = new ByAll(By.Name("cheese"));

            // one element
            Assert.Throws<NoSuchElementException>(() => by.FindElement(driver));
            Assert.That(by.FindElements(driver), Is.EqualTo(empty));

            mock.VerifyAllExpectationsHaveBeenMet();
        }
Пример #13
0
        public void FindElementOneByEmpty()
        {
            var mock   = new MockFactory();
            var driver = mock.CreateMock <IAllDriver>();
            var empty  = new List <IWebElement>().AsReadOnly();

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

            var by = new ByAll(By.Name("cheese"));

            // one element
            Assert.Throws <NoSuchElementException>(() => by.FindElement(driver.MockObject));
            Assert.That(by.FindElements(driver.MockObject), Is.EqualTo(empty));

            mock.VerifyAllExpectationsHaveBeenMet();
        }
Пример #14
0
        public void FindElementOneByEmpty()
        {
            var mock   = new Mockery();
            var driver = mock.NewMock <IAllDriver>();
            var empty  = new List <IWebElement>().AsReadOnly();

            Expect.AtLeastOnce.On(driver).Method("FindElementsByName").With("cheese").Will(Return.Value(empty));

            var by = new ByAll(By.Name("cheese"));

            // one element
            Assert.Throws <NoSuchElementException>(() => by.FindElement(driver));
            Assert.That(by.FindElements(driver), Is.EqualTo(empty));

            mock.VerifyAllExpectationsHaveBeenMet();
        }
Пример #15
0
        public void FindElementOneBy()
        {
            var mock = new Mockery();
            var driver = mock.NewMock<IAllDriver>();
            var elem1 = mock.NewMock<IAllElement>();
            var elem2 = mock.NewMock<IAllElement>();
            var elems12 = new List<IWebElement> { elem1, elem2 }.AsReadOnly();
            Expect.AtLeastOnce.On(driver).Method("FindElementsByName").With("cheese").Will(Return.Value(elems12));
            var by = new ByAll(By.Name("cheese"));

            // findElement
            Assert.AreEqual(by.FindElement(driver), elem1);
            //findElements
            Assert.That(by.FindElements(driver), Is.EqualTo(elems12));

            mock.VerifyAllExpectationsHaveBeenMet();
        }
Пример #16
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;
        }
Пример #17
0
        public void FindElementOneBy()
        {
            var driver = new Mock <IAllDriver>();
            var elem1 = new Mock <IAllElement>();
            var 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);
            var by = new ByAll(By.Name("cheese"));

            // findElement
            Assert.AreEqual(by.FindElement(driver.Object), elem1.Object);
            //findElements
            Assert.That(by.FindElements(driver.Object), Is.EqualTo(elems12));

            driver.Verify(_ => _.FindElementsByName("cheese"), Times.AtLeastOnce);
        }
Пример #18
0
        public void FindElementOneBy()
        {
            var mock = new Mockery();
            var driver = mock.NewMock <IAllDriver>();
            var elem1 = mock.NewMock <IAllElement>();
            var elem2 = mock.NewMock <IAllElement>();
            var elems12 = new List <IWebElement> {
                elem1, elem2
            }.AsReadOnly();

            Expect.AtLeastOnce.On(driver).Method("FindElementsByName").With("cheese").Will(Return.Value(elems12));
            var by = new ByAll(By.Name("cheese"));

            // findElement
            Assert.AreEqual(by.FindElement(driver), elem1);
            //findElements
            Assert.That(by.FindElements(driver), Is.EqualTo(elems12));

            mock.VerifyAllExpectationsHaveBeenMet();
        }
Пример #19
0
        public void FindElementOneBy()
        {
            var mock = new MockFactory();
            var driver = mock.CreateMock <IAllDriver>();
            var elem1 = mock.CreateMock <IAllElement>();
            var elem2 = mock.CreateMock <IAllElement>();
            var elems12 = new List <IWebElement> {
                elem1.MockObject, elem2.MockObject
            }.AsReadOnly();

            driver.Expects.AtLeastOne.Method(_ => _.FindElementsByName(null)).With("cheese").WillReturn(elems12);
            var by = new ByAll(By.Name("cheese"));

            // findElement
            Assert.AreEqual(by.FindElement(driver.MockObject), elem1.MockObject);
            //findElements
            Assert.That(by.FindElements(driver.MockObject), Is.EqualTo(elems12));

            mock.VerifyAllExpectationsHaveBeenMet();
        }
        /// <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();
        }
Пример #21
0
        public void FindElementDisjunct()
        {
            var mocks = new Mockery();
            var driver = mocks.NewMock<IAllDriver>();

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

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

            var by = new ByAll(By.Name("cheese"), By.Name("photo"));
            
            Assert.Throws<NoSuchElementException>(() => by.FindElement(driver));

            var result = by.FindElements(driver);
            Assert.That(result.Count, Is.EqualTo(0));
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Пример #22
0
        public void FindElementTwoBy()
        {
            var mocks = new Mockery();
            var driver = mocks.NewMock<IAllDriver>();

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

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

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

            // findElement
            Assert.That(by.FindElement(driver), Is.EqualTo(elem2));

            //findElements
            var result = by.FindElements(driver);
            Assert.That(result.Count, Is.EqualTo(1));
            Assert.That(result[0], Is.EqualTo(elem2));

            mocks.VerifyAllExpectationsHaveBeenMet();
        }