public void LocateElements_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.LocateElements(_bys);

            searchContextMock.Verify(x => x.FindElements(It.IsAny <By>()), Times.Exactly(_bys.Count()));
        }
        public void LocateElements_ReturnsEmptyListWhenNothingIsFound(
            [Frozen] Mock <ISearchContext> searchContextMock,
            DefaultElementLocator sut)
        {
            searchContextMock.Setup(x => x.FindElements(_bys.First()))
            .Throws(new NoSuchElementException());
            searchContextMock.Setup(x => x.FindElements(_bys.Last()))
            .Throws(new NoSuchElementException());

            sut.LocateElements(_bys).Should().BeEmpty();
        }
        public void LocateElements_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.LocateElements(_bys).Should().OnlyContain(x => x == webElementMock.Object);

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