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).Should(Have.Attribute(value = «initial»))", lines);
                Assert.Contains("Reason:", lines);
                Assert.Contains(
                    "no such element: Unable to locate element: "
                    + "{\"method\":\"css selector\",\"selector\":\"input\"}"
                    ,
                    lines
                    );
            }
        }
示例#2
0
        public void SetValue_ViaConfiguredGloballyToJs_SetsItFasterThanNormalSetValue()
        {
            Configuration.SetValueByJs = false;
            Given.OpenedPageWithBody(@"
                <input id='field1' value='should be cleared'>
                <input id='field2' value='should be cleared'>
            ");
            var beforeType = DateTime.Now;

            S("#field1").SetValue(new string('*', 200));
            var afterType    = DateTime.Now;
            var setValueTime = afterType - beforeType;

            var beforeJsSetValue = afterType;

            Configuration.SetValueByJs = true;
            S("#field2").SetValue(new string('*', 200));
            var afterJsSetValue = DateTime.Now;

            // THEN
            S("#field1").Should(Have.Value(new string('*', 200)));
            S("#field2").Should(Have.Value(new string('*', 200)));

            var jsTime = afterJsSetValue - beforeJsSetValue;

            Assert.Less(jsTime, setValueTime / 2);
        }
        public void Type_ViaElementCustomizedToJs_SetsItFasterThanNormalType()
        {
            Configuration.TypeByJs = false;
            Given.OpenedPageWithBody(@"
                <input id='field1' value='prefix to append to '>
                <input id='field2' value='prefix to append to '>
            ");
            var beforeType = DateTime.Now;

            S("#field1").Type(new string('*', 100));
            var afterType    = DateTime.Now;
            var setValueTime = afterType - beforeType;

            var beforeJsSetValue = afterType;

            S("#field2").With(typeByJs: true).Type(new string('*', 100));
            var afterJsSetValue = DateTime.Now;

            // THEN
            S("#field1").Should(Have.Value("prefix to append to " + new string('*', 100)));
            S("#field2").Should(Have.Value("prefix to append to " + new string('*', 100)));

            var jsTime = afterJsSetValue - beforeJsSetValue;

            Assert.Less(jsTime, setValueTime / 2.0);
        }
示例#4
0
 public void SElementShouldHaveValue()
 {
     Given.OpenedEmptyPage();
     Selene.S("input").ShouldNot(Have.Value("Yo"));
     When.WithBody("<input value='Yo'></input>");
     Selene.S("input").ShouldNot(Have.Value("o_O"));
     Selene.S("input").Should(Have.Value("Yo"));
 }
示例#5
0
 public void HaveValue()
 {
     Given.OpenedEmptyPage();
     S("input").Should(Have.No.Value("Yo"));
     When.WithBody("<input value='Yo'></input>");
     S("input").Should(Have.No.Value("o_O"));
     S("input").Should(Have.Value("Yo"));
 }
示例#6
0
 public void SeleneElement_Should_FailsWhenAssertingWrongValueForElement()
 {
     Configuration.Timeout = 0.2;
     Given.OpenedPageWithBody("<input id='new-text' type='text' value='ku ku' style='display:none'/>");
     Assert.Throws(Is.TypeOf(typeof(WebDriverTimeoutException))
                   .And.Message.Contains("for condition: value='ka ku'")
                   .And.Message.Contains("Actual: value='ku ku'"), () => {
         S("#new-text").Should(Have.Value("ka ku"));
     });
 }
        public void Should_HaveValue_Or_HaveText_IsRenderedInError_OnDifferentActualAsEmptyFailure()
        {
            Configuration.Timeout         = 0.25;
            Configuration.PollDuringWaits = 0.1;
            Given.OpenedPageWithBody(
                @"
                <label value='some'>thing</label>
                "
                );
            var beforeCall = DateTime.Now;

            try
            {
                S("label").Should(Have.Value("").Or(Have.ExactText("")));
            }

            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(label).Should(Have.Attribute(value = «») OR Have.ExactText(«»))", lines);
                Assert.Contains("Reason:", lines);
                Assert.Contains("Actual value: «some»", lines);
                Assert.Contains(
                    "Actual webelement: <label value=\"some\">thing</label>",
                    lines
                    );
                Assert.Contains("Actual text: «thing»", lines);
                Assert.Contains( // this line will be repeated twice; we mention it here just to remember to refactor in future
                    "Actual webelement: <label value=\"some\">thing</label>",
                    lines
                    );
            }
        }
        public void Should_HaveValue_WaitsForPresenceInDom_OfInitiialyAbsent()
        {
            Configuration.Timeout         = 0.6;
            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(0.6));
        }
        public void Should_HaveValue_IsRenderedInError_OnDifferentActualAsEmptyFailure()
        {
            Configuration.Timeout         = 0.25;
            Configuration.PollDuringWaits = 0.1;
            Given.OpenedPageWithBody(
                @"
                <input value='' style='display:none'></input>
                "
                );
            var beforeCall = DateTime.Now;

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

            catch (TimeoutException error)
            {
                var afterCall = DateTime.Now;
                Assert.Greater(afterCall, beforeCall.AddSeconds(0.25));
                var accuracyDelta = 0.25;
                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).Should(Have.Attribute(value = «some»))", lines);
                Assert.Contains("Reason:", lines);
                Assert.Contains("Actual value: «»", lines);
                Assert.Contains(
                    "Actual webelement: <input value=\"\" style=\"display:none\">",
                    lines
                    );
            }
        }
        public void JsSetValue_SetsItFasterThanSendKeysLikeType()
        {
            Given.OpenedPageWithBody(@"
                <input id='field1'>
                <input id='field2'>
            ");

            var beforeType = DateTime.Now;

            S("#field1").Type(new string('*', 200));
            var afterType        = DateTime.Now;
            var typeTime         = afterType - beforeType;
            var beforeJsSetValue = afterType;

            S("#field2").JsSetValue(new string('*', 200));
            var afterJsSetValue = DateTime.Now;
            var jsTime          = afterJsSetValue - beforeJsSetValue;

            S("#field1").Should(Have.Value(new string('*', 200)));
            S("#field2").Should(Have.Value(new string('*', 200)));

            Assert.Less(jsTime, typeTime / 2.0);
        }