public void LocateElement_CallsSearchContext([Frozen] Mock <ISearchContext> searchContextMock,
                                                     [Frozen] Mock <IWebElement> elementMock,
                                                     DefaultElementLocator sut)
        {
            searchContextMock.Setup(x => x.FindElements(It.IsAny <By>())).Returns(new ReadOnlyCollection <IWebElement>(new[] { elementMock.Object }.ToList()));

            sut.LocateElement(_bys);

            searchContextMock.Verify(x => x.FindElements(It.IsAny <By>()), Times.Once());
        }
        public void LocateElement_ThrowsExceptionWhenNothingIsFound([Frozen] Mock <ISearchContext> searchContextMock)
        {
            var sut = new DefaultElementLocator(searchContextMock.Object, TimeSpan.FromMilliseconds(5),
                                                TimeSpan.FromMilliseconds(20));

            searchContextMock.Setup(x => x.FindElements(_bys.First()))
            .Throws(new NoSuchElementException());
            searchContextMock.Setup(x => x.FindElements(_bys.Last()))
            .Throws(new NoSuchElementException());

            Action action = () => sut.LocateElement(_bys);

            action.Should().Throw <NoSuchElementException>();
        }
        public void LocateElement_IteratesBysUntilAnyWasFound(
            [Frozen] Mock <ISearchContext> searchContextMock,
            Mock <IWebElement> webElementMock,
            DefaultElementLocator sut)
        {
            searchContextMock.Setup(x => x.FindElements(_bys.First()))
            .Throws(new NoSuchElementException());
            searchContextMock.Setup(x => x.FindElements(_bys.Last()))
            .Returns(new ReadOnlyCollection <IWebElement>(new[] { webElementMock.Object }));

            sut.LocateElement(_bys).Should().Be(webElementMock.Object);

            searchContextMock.Verify(x => x.FindElements(_bys.First()), Times.AtLeastOnce());
            searchContextMock.Verify(x => x.FindElements(_bys.Last()), Times.AtLeastOnce());
        }
 public void LocateElement_ArgumentNullExceptions(DefaultElementLocator sut)
 {
     new Action(() => sut.LocateElement(null)).Should().Throw <ArgumentNullException>();
 }