Ejemplo n.º 1
0
            public void When_index_is_between_0_and_2_Then_returns_webElement_at_matching_index(
                int index,
                IFindsByFluentSelector <IWebElement> webDriver,
                [Frozen] IReadOnlyCollection <IWebElement> webElements,
                string locator,
                string value
                )
            {
                // Arrange
                var expected = webElements.ElementAt(index);

                Mock.Get(webDriver).Setup(x => x.FindElements(locator, value)).Returns(webElements);
                var sut = new SearchProperty <IWebElement>(
                    locator,
                    value,
                    webDriver,
                    index,
                    150.Milliseconds());

                // Act
                var actual = sut.Find();

                // Assert
                actual.ShouldBe(expected);
            }
Ejemplo n.º 2
0
            public void When_index_is_between_0_and_2_Then_returns_webElement_at_matching_index(
                int index,
                IFindsByFluentSelector <IWebElement> webDriver,
                [Frozen] IReadOnlyCollection <IWebElement> webElements,
                string locator,
                string value
                )
            {
                // Arrange
                var expected = webElements.ElementAt(index);

                using var cancellationTokenSource1 = new CancellationTokenSource(TimeSpan.FromMilliseconds(100));
                using var cancellationTokenSource2 = new CancellationTokenSource(TimeSpan.FromMilliseconds(130));
                var cancellationToken1 = cancellationTokenSource1.Token;
                var cancellationToken2 = cancellationTokenSource2.Token;

                Mock.Get(webDriver).Setup(x => x.FindElements(locator, value)).Returns(webElements);
                var sut = new SearchProperty <IWebElement>(locator, value, webDriver, index, 200.Milliseconds());

                // Act
                var actual = sut.Get(cancellationToken1, cancellationToken2);

                // Assert
                actual.ShouldBe(expected);
            }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SearchProperty"/> class.
 /// </summary>
 /// <param name="selector">The selector to use to search the WebElement.</param>
 /// <param name="value">The expected value of the WebElement selector.</param>
 /// <param name="webDriver">The WebDriver.</param>
 /// <param name="defaultTimeout">The default timeout used to cancel the task as soon as possible.</param>
 public SearchProperty(
     string selector,
     string value,
     IFindsByFluentSelector <W> webDriver,
     TimeSpan defaultTimeout)
     : this(selector, value, webDriver, 0, defaultTimeout)
 {
 }
Ejemplo n.º 4
0
        public void When_no_defaultCancellationToken_Then_DefaultCancellationToken_is_None(
            int index,
            IFindsByFluentSelector <IWebElement> webDriver,
            string locator,
            string value)
        {
            // Arrange, Act
            var actual = new SearchProperty <IWebElement>(locator, value, webDriver, index, TimeSpan.Zero);

            // Assert
            actual.DefaultTimeout.ShouldBe(TimeSpan.Zero);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SearchProperty"/> class.
 /// </summary>
 /// <param name="selector">The selector to use to search the WebElement.</param>
 /// <param name="value">The expected value of the WebElement selector.</param>
 /// <param name="webDriver">The WebDriver.</param>
 /// <param name="index">The index of the expected WebElement from a list of matching WebElement.</param>
 /// <param name="defaultTimeout">The default timeout used to cancel the task as soon as possible.</param>
 public SearchProperty(
     string selector,
     string value,
     IFindsByFluentSelector <W> webDriver,
     int index,
     TimeSpan defaultTimeout)
 {
     Selector       = selector ?? throw new ArgumentNullException(nameof(selector));
     Value          = value ?? throw new ArgumentNullException(nameof(value));
     WebDriver      = webDriver ?? throw new ArgumentNullException(nameof(webDriver));
     Index          = index;
     DefaultTimeout = defaultTimeout;
 }
Ejemplo n.º 6
0
        public void When_all_parameters_are_valid_Then_returns_SearchProperties(
            int index,
            IFindsByFluentSelector <IWebElement> webDriver,
            string locator,
            string value)
        {
            // Arrange, Act
            var actual = new SearchProperty <IWebElement>(locator, value, webDriver, index, 100.Milliseconds());

            // Assert
            actual.ShouldNotBeNull();
            actual.ShouldBeAssignableTo <ISearchProperty <IWebElement> >();
        }
Ejemplo n.º 7
0
        public void When_all_parameters_are_valid_Then_assigned_public_properties(
            int index,
            IFindsByFluentSelector <IWebElement> webDriver,
            string locator,
            string value)
        {
            // Arrange, Act
            var actual = new SearchProperty <IWebElement>(locator, value, webDriver, index, 100.Milliseconds());

            // Assert
            actual.Selector.ShouldBe(locator);
            actual.Value.ShouldBe(value);
            actual.WebDriver.ShouldBe(webDriver);
            actual.Index.ShouldBe(index);
        }
Ejemplo n.º 8
0
        public void When_no_index_is_defined_Then_Index_is_0(
            IFindsByFluentSelector <IWebElement> webDriver,
            string locator,
            string value)
        {
            // Arrange, Act
            var actual = new SearchProperty <IWebElement>(
                locator,
                value,
                webDriver,
                100.Milliseconds());

            // Assert
            actual.Index.ShouldBe(0);
        }
Ejemplo n.º 9
0
            public void When_index_is_out_of_range_Then_throws_TimeoutException(
                IFindsByFluentSelector <IWebElement> webDriver,
                [Frozen] IReadOnlyCollection <IWebElement> webElements,
                string locator,
                string value)
            {
                // Arrange
                var timeout         = 100.Milliseconds();
                int indexOutOfRange = webElements.Count + 1;

                Mock.Get(webDriver).Setup(x => x.FindElements(locator, value)).Returns(webElements);
                var sut = new SearchProperty <IWebElement>(locator, value, webDriver, indexOutOfRange, 150.Milliseconds());

                // Assert
                Assert.Throws <TimeoutException>(() => sut.Find(timeout));
            }
Ejemplo n.º 10
0
            public void When_index_is_not_defined_Then_returns_first_WebElement(
                IFindsByFluentSelector <IWebElement> webDriver,
                [Frozen] IReadOnlyCollection <IWebElement> webElements,
                string locator,
                string value)
            {
                // Arrange
                Mock.Get(webDriver).Setup(x => x.FindElements(locator, value)).Returns(webElements);
                var sut = new SearchProperty <IWebElement>(locator, value, webDriver, 100.Milliseconds());

                // Act
                var actual = sut.Get();

                // Assert
                actual.ShouldBe(webElements.First());
            }
Ejemplo n.º 11
0
            public void When_index_is_out_of_range_Then_throws_OperationCanceledException(
                IFindsByFluentSelector <IWebElement> webDriver,
                [Frozen] IReadOnlyCollection <IWebElement> webElements,
                string locator,
                string value)
            {
                // Arrange
                using var cancellationTokenSource = new CancellationTokenSource(50.Milliseconds());
                int indexOutOfRange   = webElements.Count + 1;
                var cancellationToken = cancellationTokenSource.Token;

                Mock.Get(webDriver).Setup(x => x.FindElements(locator, value)).Returns(webElements);
                var sut = new SearchProperty <IWebElement>(locator, value, webDriver, indexOutOfRange, 100.Milliseconds());

                // Assert
                Assert.Throws <OperationCanceledException>(() => sut.Find(cancellationToken));
            }
Ejemplo n.º 12
0
            public void When_index_is_out_of_range_Then_returns_null(
                IFindsByFluentSelector <IWebElement> webDriver,
                [Frozen] IReadOnlyCollection <IWebElement> webElements,
                string locator,
                string value)
            {
                // Arrange
                Mock.Get(webDriver).Setup(x => x.FindElements(locator, value)).Returns(webElements);
                int indexOutOfRange = webElements.Count + 1;
                var sut             = new SearchProperty <IWebElement>(locator, value, webDriver, indexOutOfRange, 100.Milliseconds());

                // Act
                var actual = sut.Get();

                // Assert
                actual.ShouldBeNull();
            }
Ejemplo n.º 13
0
        public void When_all_parameters_are_valid_Then_assigned_public_properties(
            IFindsByFluentSelector <IWebElement> webDriver,
            string locator,
            string value)
        {
            // Act
            var actual = new SearchProperty <IWebElement>(
                locator,
                value,
                webDriver,
                50.Milliseconds());

            // Assert
            actual.DefaultTimeout.ShouldBe(50.Milliseconds());
            actual.Selector.ShouldBe(locator);
            actual.Value.ShouldBe(value);
            actual.WebDriver.ShouldBe(webDriver);
        }
Ejemplo n.º 14
0
        public void When_all_parameters_are_valid_Then_assigned_public_properties(
            int index,
            IFindsByFluentSelector <IWebElement> webDriver,
            string locator,
            string value)
        {
            // Act
            var actual = new SearchProperty <IWebElement>(
                locator,
                value,
                webDriver,
                index,
                TimeSpan.Zero);

            // Assert
            actual.DefaultTimeout.ShouldBe(TimeSpan.Zero);
            actual.Selector.ShouldBe(locator);
            actual.Value.ShouldBe(value);
            actual.WebDriver.ShouldBe(webDriver);
            actual.Index.ShouldBe(index);
        }
Ejemplo n.º 15
0
            public void When_index_is_not_defined_Then_returns_first_WebElement(
                IFindsByFluentSelector <IWebElement> webDriver,
                [Frozen] IReadOnlyCollection <IWebElement> webElements,
                string locator,
                string value)
            {
                // Arrange
                using var cancellationTokenSource1 = new CancellationTokenSource(TimeSpan.FromMilliseconds(50));
                using var cancellationTokenSource2 = new CancellationTokenSource(TimeSpan.FromMilliseconds(70));
                var cancellationToken1 = cancellationTokenSource1.Token;
                var cancellationToken2 = cancellationTokenSource2.Token;

                Mock.Get(webDriver).Setup(x => x.FindElements(locator, value)).Returns(webElements);
                var sut = new SearchProperty <IWebElement>(locator, value, webDriver, 100.Milliseconds());

                // Act
                var actual = sut.Get(cancellationToken1, cancellationToken2);

                // Assert
                actual.ShouldBe(webElements.First());
            }
Ejemplo n.º 16
0
            public void When_try_to_find_Then_throws_OperationCanceledException(
                int index,
                IFindsByFluentSelector <IWebElement> webDriver,
                [Frozen] IReadOnlyCollection <IWebElement> webElements,
                string locator,
                string value
                )
            {
                // Arrange
                var expected = webElements.ElementAt(index);

                Mock.Get(webDriver).Setup(x => x.FindElements(locator, value)).Returns(webElements);
                var sut = new SearchProperty <IWebElement>(
                    locator,
                    value,
                    webDriver,
                    index,
                    TimeSpan.Zero);

                // Act, Assert
                Assert.Throws <OperationCanceledException>(() => sut.Find());
            }
Ejemplo n.º 17
0
            public void When_the_webElement_is_found_Then_returns_True(
                int index,
                IFindsByFluentSelector <IWebElement> webDriver,
                [Frozen] IReadOnlyCollection <IWebElement> webElements,
                string locator,
                string value
                )
            {
                // Arrange
                Mock.Get(webDriver).Setup(x => x.FindElements(locator, value)).Returns(webElements);
                var sut = new SearchProperty <IWebElement>(
                    locator,
                    value,
                    webDriver,
                    index,
                    150.Milliseconds());

                // Act
                var actual = sut.Exist();

                // Assert
                actual.Should().Be(true);
            }
Ejemplo n.º 18
0
            public void When_the_webElement_is_not_found_Then_returns_False(
                int index,
                IFindsByFluentSelector <IWebElement> webDriver,
                string locator,
                string value
                )
            {
                // Arrange
                var emptyElementCollection = new ReadOnlyCollection <IWebElement>(new List <IWebElement>());

                Mock.Get(webDriver).Setup(x => x.FindElements(locator, value)).Returns(emptyElementCollection);
                var sut = new SearchProperty <IWebElement>(
                    locator,
                    value,
                    webDriver,
                    index,
                    150.Milliseconds());

                // Act
                var actual = sut.Exist();

                // Assert
                actual.Should().Be(false);
            }