Example #1
0
        public void Should_HaveValue_IsRenderedInError_OnAbsentElementTimeoutFailure()
        {
            Configuration.Timeout         = 0.25;
            Configuration.PollDuringWaits = 0.1;
            Given.OpenedEmptyPage();
            var beforeCall = DateTime.Now;

            try
            {
                S("input").Should(Have.Value("initial"));
            }

            catch (TimeoutException error)
            {
                var afterCall = DateTime.Now;
                Assert.Greater(afterCall, beforeCall.AddSeconds(0.25));
                var accuracyDelta = 0.2;
                Assert.Less(afterCall, beforeCall.AddSeconds(0.25 + 0.1 + accuracyDelta));

                // TODO: shoud we check timing here too?
                var lines = error.Message.Split("\n").Select(
                    item => item.Trim()
                    ).ToList();

                Assert.Contains("Timed out after 0.25s, while waiting for:", lines);
                Assert.Contains("Browser.Element(input).value='initial'", lines);
                Assert.Contains("Reason:", lines);
                Assert.Contains(
                    "no such element: Unable to locate element: "
                    + "{\"method\":\"css selector\",\"selector\":\"input\"}"
                    ,
                    lines
                    );
            }
        }
Example #2
0
        public void Should_HaveCount_IsRenderedInError_OnAbsentElementTimeoutFailure()
        {
            Configuration.Timeout         = 0.25;
            Configuration.PollDuringWaits = 0.1;
            Given.OpenedEmptyPage();
            var beforeCall = DateTime.Now;

            try
            {
                SS("p").Should(Have.Count(2));
            }

            catch (TimeoutException error)
            {
                var afterCall = DateTime.Now;
                Assert.Greater(afterCall, beforeCall.AddSeconds(0.25));
                var accuracyDelta = 0.2;
                Assert.Less(afterCall, beforeCall.AddSeconds(0.25 + 0.1 + accuracyDelta));

                // TODO: shoud we check timing here too?
                var lines = error.Message.Split("\n").Select(
                    item => item.Trim()
                    ).ToList();

                Assert.Contains("Timed out after 0.25s, while waiting for:", lines);
                Assert.Contains("Browser.All(p).Should(count = 2)", lines);
                Assert.Contains("Reason:", lines);
                Assert.Contains("actual: count = 0", lines);
            }
        }
Example #3
0
        public void Should_HaveCount_WaitsForAsked_OfInitialyOtherVisibleCount()
        {
            Configuration.Timeout         = 0.6;
            Configuration.PollDuringWaits = 0.1;
            Given.OpenedPageWithBody(
                @"
                <p>a</p>
                "
                );
            var beforeCall = DateTime.Now;

            Given.OpenedPageWithBodyTimedOut(
                @"
                <p>a</p>
                <p>b</p>
                "
                ,
                300
                );

            SS("p").Should(Have.Count(2));

            var afterCall = DateTime.Now;

            Assert.Greater(afterCall, beforeCall.AddSeconds(0.3));
            Assert.Less(afterCall, beforeCall.AddSeconds(0.6));
            Assert.AreEqual(
                2,
                Configuration.Driver
                .FindElements(By.TagName("p")).Count
                );
        }
Example #4
0
        public void Should_HaveText_IsRenderedInError_OnElementDifferentTextFailure()
        {
            Configuration.Timeout         = 0.25;
            Configuration.PollDuringWaits = 0.1;
            Given.OpenedPageWithBody(
                @"
                <label>initial</label>
                "
                );

            try
            {
                S("label").Should(Have.Text("new"));
            }

            catch (TimeoutException error)
            {
                var lines = error.Message.Split("\n").Select(
                    item => item.Trim()
                    ).ToList();

                Assert.Contains("Timed out after 0.25s, while waiting for:", lines);
                Assert.Contains("Browser.Element(label).TextContaining(«new»)", lines);
                Assert.Contains("Reason:", lines);
                Assert.Contains("Actual text: «initial»", lines);
                Assert.Contains("Actual webelement: <label>initial</label>", lines);

                Assert.AreEqual(
                    "initial", Configuration.Driver.FindElement(By.TagName("label")).Text
                    );
            }
        }
Example #5
0
        public void Should_HaveText_WaitsForVisibility_OfInitialyHidden()
        {
            Configuration.Timeout         = 0.6;
            Configuration.PollDuringWaits = 0.1;
            Given.OpenedPageWithBody(
                @"
                <label style='display:none'>initial</label>
                "
                );
            var beforeCall = DateTime.Now;

            Given.ExecuteScriptWithTimeout(
                @"
                document.getElementsByTagName('label')[0].style.display = 'block';
                ",
                300
                );

            S("label").Should(Have.Text("initial"));

            var afterCall = DateTime.Now;

            Assert.Greater(afterCall, beforeCall.AddSeconds(0.3));
            Assert.Less(afterCall, beforeCall.AddSeconds(0.6));
            Assert.AreEqual(
                "initial",
                Configuration.Driver
                .FindElement(By.TagName("label")).Text
                );
        }
Example #6
0
        public void SeleneWaitTo_HaveJsReturned_WaitsForPresenceInDom_OfInitiialyAbsent()
        {
            Configuration.Timeout         = 0.6;
            Configuration.PollDuringWaits = 0.1;
            Given.OpenedEmptyPage();
            var beforeCall = DateTime.Now;

            Given.OpenedPageWithBodyTimedOut(
                @"
                <p style='display:none'>a</p>
                <p style='display:none'>b</p>
                ",
                300
                );

            Selene.WaitTo(Have.JSReturnedTrue(
                              @"
                var expectedCount = arguments[0]
                return document.getElementsByTagName('p').length == expectedCount
                "
                              ,
                              2
                              ));

            var afterCall = DateTime.Now;

            Assert.Greater(afterCall, beforeCall.AddSeconds(0.3));
            Assert.Less(afterCall, beforeCall.AddSeconds(0.6));
        }
Example #7
0
        public void SeleneWaitTo_HaveJsReturned_IsRenderedInError_OnAbsentElementTimeoutFailure()
        {
            Configuration.Timeout         = 0.25;
            Configuration.PollDuringWaits = 0.1;
            Given.OpenedEmptyPage();
            var beforeCall = DateTime.Now;

            try
            {
                Selene.WaitTo(Have.JSReturnedTrue(
                                  @"
                    var expectedCount = arguments[0]
                    return document.getElementsByTagName('p').length == expectedCount
                    "
                                  ,
                                  2
                                  ));
            }

            catch (WebDriverTimeoutException error)
            {
                var afterCall = DateTime.Now;
                Assert.Greater(afterCall, beforeCall.AddSeconds(0.25));
                var accuracyDelta = 0.2;
                Assert.Less(afterCall, beforeCall.AddSeconds(0.25 + 0.1 + accuracyDelta));

                // TODO: shoud we check timing here too?
                var lines = error.Message.Split("\n").Select(
                    item => item.Trim()
                    ).ToList();

                Assert.Contains("Timed out after 0.25 seconds", lines);
                Assert.Contains("while waiting entity with locator: OpenQA.Selenium.Chrome.ChromeDriver", lines);
                Assert.Contains("for condition: JSReturnedTrue", lines);
            }

            // catch (TimeoutException error)
            // {
            //     var afterCall = DateTime.Now;
            //     Assert.Greater(afterCall, beforeCall.AddSeconds(0.25));
            //     var accuracyDelta = 0.2;
            //     Assert.Less(afterCall, beforeCall.AddSeconds(0.25 + 0.1 + accuracyDelta));

            //     // TODO: shoud we check timing here too?
            //     var lines = error.Message.Split("\n").Select(
            //         item => item.Trim()
            //     ).ToList();

            //     Assert.Contains("Timed out after 0.25s, while waiting for:", lines);
            //     Assert.Contains("Browser.All(p).count = 2", lines);
            //     Assert.Contains("Reason:", lines);
            //     Assert.Contains("actual: count = 0", lines);
            // }
        }
Example #8
0
        public void Should_HaveText_DoesNotWaitForNoOverlay() // TODO: but should it?
        {
            Configuration.Timeout         = 0.6;
            Configuration.PollDuringWaits = 0.1;
            Given.OpenedPageWithBody(
                @"
                <div 
                    id='overlay' 
                    style='
                        display:block;
                        position: fixed;
                        display: block;
                        width: 100%;
                        height: 100%;
                        top: 0;
                        left: 0;
                        right: 0;
                        bottom: 0;
                        background-color: rgba(0,0,0,0.1);
                        z-index: 2;
                        cursor: pointer;
                    '
                >
                </div>

                <label>initial</label>
                "
                );
            var beforeCall = DateTime.Now;

            Given.ExecuteScriptWithTimeout(
                @"
                document.getElementById('overlay').style.display = 'none';
                ",
                300
                );

            S("label").Should(Have.Text("initial"));

            var afterCall = DateTime.Now;

            Assert.Less(afterCall, beforeCall.AddSeconds(0.3));
            Assert.AreEqual(
                "initial",
                Configuration.Driver
                .FindElement(By.TagName("label")).Text
                );
            // Assert.Greater(afterCall, beforeCall.AddSeconds(0.3));
            // Assert.Less(afterCall, beforeCall.AddSeconds(0.6));
        }
Example #9
0
        public void Should_HaveValue_WaitsForPresenceInDom_OfInitiialyAbsent()
        {
            Configuration.Timeout         = 1.0;
            Configuration.PollDuringWaits = 0.1;
            Given.OpenedEmptyPage();
            var beforeCall = DateTime.Now;

            Given.OpenedPageWithBodyTimedOut(
                @"
                <input value='initial' style='display:none'></input>
                ",
                300
                );

            S("input").Should(Have.Value("initial"));
            var afterCall = DateTime.Now;

            Assert.Greater(afterCall, beforeCall.AddSeconds(0.3));
            Assert.Less(afterCall, beforeCall.AddSeconds(1.0));
        }
Example #10
0
        public void Should_HaveCount_WaitsForPresenceInDom_OfInitiialyAbsent()
        {
            Configuration.Timeout         = 0.6;
            Configuration.PollDuringWaits = 0.1;
            Given.OpenedEmptyPage();
            var beforeCall = DateTime.Now;

            Given.OpenedPageWithBodyTimedOut(
                @"
                <p style='display:none'>a</p>
                <p style='display:none'>b</p>
                ",
                300
                );

            SS("p").Should(Have.Count(2));
            var afterCall = DateTime.Now;

            Assert.Greater(afterCall, beforeCall.AddSeconds(0.3));
            Assert.Less(afterCall, beforeCall.AddSeconds(0.6));
        }
Example #11
0
        public void Should_HaveText_WaitsForAskedText_OfInitialyOtherText()
        {
            Configuration.Timeout         = 0.6;
            Configuration.PollDuringWaits = 0.1;
            Given.OpenedPageWithBody(
                @"
                <label>initial</label>
                "
                );
            var beforeCall = DateTime.Now;

            Given.OpenedPageWithBodyTimedOut(
                @"
                <label>new</label>
                "
                ,
                300
                );

            S("label").Should(Have.Text("new"));

            var afterCall = DateTime.Now;

            Assert.Greater(afterCall, beforeCall.AddSeconds(0.3));
            Assert.Less(afterCall, beforeCall.AddSeconds(0.6));
            Assert.AreEqual(
                "new",
                Configuration.Driver
                .FindElement(By.TagName("label")).Text
                );
            Assert.AreEqual(
                "new",
                Configuration.Driver
                .FindElement(By.TagName("label")).Text
                );
        }