예제 #1
0
 public void SElementShouldHaveAttribute()
 {
     Given.OpenedPageWithBody("<h1 class='big-title'>Hello Babe!</h1>");
     Selene.S("h1").ShouldNot(Have.Attribute("class", "big title"));
     When.WithBody("<h1 class='big title'>Hello world!</h1>");
     Selene.S("h1").Should(Have.Attribute("class", "big title"));
 }
예제 #2
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));
        }
예제 #3
0
        private static void handleIncomingData(BinaryReader br, IPEndPoint peerAddress)
        {
            var data = new Data();

            data.Decode(br);

            Console.WriteLine("DATA Size: {0} Chunk: {1}", data.DataBytes.Length, data.BinValue);

            var haveMessage = new Have();

            haveMessage.DestChannelId = _sendingChannel;
            haveMessage.BinValue      = data.BinValue;

            var ackMessage = new Ack();

            ackMessage.BinValue = data.BinValue;

            var requestMessage = new Request();

            requestMessage.BinValue = data.BinValue + 40;

            var returnBytes = new List <byte>();

            returnBytes.AddRange(haveMessage.ToByteArray());
            returnBytes.AddRange(requestMessage.ToByteArray());

            _client.Send(returnBytes.ToArray(), returnBytes.Count, peerAddress);
        }
        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);
        }
        public void SEeleneCollectionSearchWithText()
        {
            String searchText      = "Dear";
            String xpathTextSearch =
                String.Format("//*[contains(text(),'{0}')]", searchText);

            // search using wrapped driver methods

            ReadOnlyCollection <IWebElement> webElements = Selene.GetWebDriver().FindElements(By.XPath(xpathTextSearch));

            Assert.NotNull(webElements);
            Assert.Greater(webElements.Count, 0);
            StringAssert.Contains(searchText, webElements[0].Text);


            // search thru NSelene
            By               seleneLocator   = NSelene.With.Text(searchText);
            IWebDriver       webDriver       = Selene.GetWebDriver();
            SeleneCollection seleWebElements = Selene.SS(seleneLocator);

            Assert.NotNull(seleWebElements);
            Assert.AreEqual(seleWebElements.Count, webElements.Count);
            StringAssert.Contains(searchText, seleWebElements[0].Text);


            // confirm all have searchText
            seleWebElements = Selene.SS(seleneLocator, webDriver);
            Assert.AreEqual(seleWebElements.FilterBy(Have.Text(searchText)).Count, seleWebElements.Count);

            // exercise NSelene extension methods
            Selene.SS(seleneLocator).Should(Have.Texts("Bob", "Frank"));
            Selene.SS(seleneLocator).ShouldNot(Have.Texts("Bob"));
            Selene.SS(seleneLocator).ShouldNot(Have.Texts("Bob", "Kate", "Frank"));
            Selene.SS(seleneLocator).Should(Have.ExactTexts("Dear Bob", "Dear Frank"));
        }
        public void ReturnsTrue_AfterWaiting_OnMatched_AfterDelayLessThanTimeout()
        {
            Configuration.Timeout = 2.000;
            var hiddenDelay  = 500;
            var visibleDelay = hiddenDelay + 250;

            Given.OpenedEmptyPage();
            var beforeCall = DateTime.Now;

            Given.WithBodyTimedOut(
                "<p id='will-appear' style='display:none'>Hello!</p>",
                hiddenDelay
                );
            Given.ExecuteScriptWithTimeout(
                "document.getElementsByTagName('p')[0].style = 'display:block';",
                visibleDelay
                );

            var result    = SS("#will-appear").WaitUntil(Have.Texts("Hello!"));
            var afterCall = DateTime.Now;

            Assert.IsTrue(result);
            Assert.IsTrue(afterCall > beforeCall.AddMilliseconds(visibleDelay));
            Assert.IsTrue(afterCall < beforeCall.AddSeconds(Configuration.Timeout));
        }
예제 #7
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 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).count = 2", lines);
                Assert.Contains("Reason:", lines);
                Assert.Contains("actual: count = 0", lines);
            }
        }
        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
                );
        }
예제 #10
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).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
                    );
            }
        }
예제 #11
0
        public void YandexTextSearch()
        {
            String emptySearchResponse = "Задан пустой поисковый запрос";

            Selene.GoToUrl("https://yandex.ru/search");
            Selene.S(With.Text(emptySearchResponse)).Should(Have.Text(emptySearchResponse));
        }
예제 #12
0
                    public void Search()
                    {
                        Open("http://google.com/ncr");

                        S(By.Name("q")).SetValue("Selenide").PressEnter();
                        SS(".srg>.g")[0].Should(Have.Text("Selenide: concise UI tests in Java"));
                    }
예제 #13
0
                public void Search()
                {
                    Google.Open();

                    Google.Search("selenide");
                    Google.Results[0].Should(Have.Text("Selenide: concise UI tests in Java"));
                }
예제 #14
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).Should(Have.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
                    );
            }
        }
예제 #15
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
                );
        }
예제 #16
0
 public void SElementShouldHaveCssClass()
 {
     Given.OpenedPageWithBody("<h1 class='big-title'>Hello Babe!</h1>");
     S("h1").ShouldNot(Have.CssClass("title"));
     When.WithBody("<h1 class='big title'>Hello world!</h1>");
     S("h1").Should(Have.CssClass("title"));
 }
예제 #17
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"));
 }
예제 #18
0
 public void SElementShouldHaveText()
 {
     Given.OpenedPageWithBody("<h1>Hello Babe!</h1>");
     Selene.S("h1").Should(Have.Text("Hello"));
     Selene.S("h1").ShouldNot(Have.Text("Hello world!"));
     Selene.S("h1").ShouldNot(Have.ExactText("Hello"));
     Selene.S("h1").Should(Have.ExactText("Hello Babe!"));
 }
예제 #19
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"));
 }
예제 #20
0
 public void HaveText()
 {
     Given.OpenedPageWithBody("<h1>Hello Babe!</h1>");
     S("h1").Should(Have.Text("Hello"));
     S("h1").Should(Have.No.Text("Hello world!"));
     S("h1").Should(Have.No.ExactText("Hello"));
     S("h1").Should(Have.ExactText("Hello Babe!"));
 }
        public void HookWaitAction_SetPerElements_CanLogActionsLikeClickAndShould()
        {
            List <string> log = new List <string>();

            Configuration.Timeout         = 0.1;
            Configuration.PollDuringWaits = 0.01;
            Action <object, Func <string>, Action> logIt = (entityObject, describeComputation, wait) =>
            {
                log.Add($"{entityObject}.{describeComputation()}: STARTED");
                try
                {
                    wait();
                    log.Add($"{entityObject}.{describeComputation()}: PASSED");
                }
                catch (Exception error)
                {
                    log.Add($"{entityObject}.{describeComputation()}: FAILED");
                    throw error;
                }
            };

            Given.OpenedPageWithBody(@"
                <button>Click me!</button>
            ");
            var button     = S("button").With(_hookWaitAction: logIt);
            var allButtons = SS("button").With(_hookWaitAction: logIt);
            var absent     = S(".absent").With(_hookWaitAction: logIt);
            var allAbsent  = SS(".absent").With(_hookWaitAction: logIt);

            allButtons.Should(Have.Count(1));
            button.Should(Have.ExactText("Click me!"));
            button.Click();
            button.With(clickByJs: true).Click();
            try { absent.Click(); } catch {}
            try { absent.Should(Have.Text("some")); } catch {}
            try { allAbsent.Should(Have.Count(1)); } catch {}
            try { absent.FindAll(".child").Should(Have.Count(1)); } catch {}

            Assert.AreEqual(log,
                            @"Browser.All(button).Should(Have.Count = 1): STARTED
                Browser.All(button).Should(Have.Count = 1): PASSED
                Browser.Element(button).Should(Have.ExactText(«Click me!»)): STARTED
                Browser.Element(button).Should(Have.ExactText(«Click me!»)): PASSED
                Browser.Element(button).ActualWebElement.Click(): STARTED
                Browser.Element(button).ActualWebElement.Click(): PASSED
                Browser.Element(button).JsClick(centerXOffset: 0, centerYOffset: 0): STARTED
                Browser.Element(button).JsClick(centerXOffset: 0, centerYOffset: 0): PASSED
                Browser.Element(.absent).ActualWebElement.Click(): STARTED
                Browser.Element(.absent).ActualWebElement.Click(): FAILED
                Browser.Element(.absent).Should(Have.TextContaining(«some»)): STARTED
                Browser.Element(.absent).Should(Have.TextContaining(«some»)): FAILED
                Browser.All(.absent).Should(Have.Count = 1): STARTED
                Browser.All(.absent).Should(Have.Count = 1): FAILED
                Browser.Element(.absent).All(.child).Should(Have.Count = 1): STARTED
                Browser.Element(.absent).All(.child).Should(Have.Count = 1): FAILED"
                            .Split("\n").Select(item => item.Trim()).ToList()
                            );
        }
예제 #22
0
 public void SCollectionShouldHaveCountAtLeastAndCount()
 {
     Given.OpenedEmptyPage();
     SS("li").ShouldNot(Have.Count(2));
     When.WithBody("<ul>Hello to:<li>Dear Bob</li><li>Lovely Kate</li></ul>");
     SS("li").ShouldNot(Have.CountAtLeast(3));
     SS("li").Should(Have.Count(2));
     SS("li").Should(Have.CountAtLeast(1));
 }
        public void FindByRequest()
        {
            var searchRequest = "TBC Bank CEO";

            _homePage.SearchByRequest(searchRequest);

            _searchResultPage.SearchResultItemByText(searchRequest)
            .Should(Have.Text(searchRequest));
        }
        public void FindByRequestOther()
        {
            var searchRequest = "PUBLIC OFFERING";

            _homePage.SearchByRequest(searchRequest);

            _searchResultPage.SearchResultItemByText(searchRequest)
            .Should(Have.Text(searchRequest));
        }
예제 #25
0
파일: Tasks.cs 프로젝트: sergueik/NSelene
 public static void Visit()
 {
     GoToUrl("https://todomvc4tasj.herokuapp.com/");
     WaitFor(GetWebDriver(), Have.JSReturnedTrue(
                 "return " +
                 "$._data($('#new-todo').get(0), 'events').hasOwnProperty('keyup')&& " +
                 "$._data($('#toggle-all').get(0), 'events').hasOwnProperty('change') && " +
                 "$._data($('#clear-completed').get(0), 'events').hasOwnProperty('click')"));
 }
예제 #26
0
         #pragma warning restore 649
 public void Visit()
 {
     Open("https://todomvc4tasj.herokuapp.com/");
     I.Should(Have.JSReturnedTrue(
                  "return " +
                  "$._data($('#new-todo').get(0), 'events').hasOwnProperty('keyup')&& " +
                  "$._data($('#toggle-all').get(0), 'events').hasOwnProperty('change') && " +
                  "$._data($('#clear-completed').get(0), 'events').hasOwnProperty('click')"));
 }
예제 #27
0
                    public void Search()
                    {
                        Open("http://google.com/ncr");

                        S(By.Name("q")).SetValue("Selenide").PressEnter();
                        SS(".srg>.g")[0].Should(Have.Text("Selenide: concise UI tests in Java"));

                        SS(".srg>.g")[0].Find("h3>a").Click();
                        wait.Until(UrlToBe("http://selenide.org/"));
                    }
예제 #28
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 ReturnsFalse_AfterWaitingTimeout_OnNotMatched_WithExceptionReason()
        {
            Configuration.Timeout = 0.75;
            var beforeCall = DateTime.Now;

            var result    = SS("#absent").WaitUntil(Have.Count(2));
            var afterCall = DateTime.Now;

            Assert.IsFalse(result);
            Assert.IsTrue(afterCall >= beforeCall.AddSeconds(Configuration.Timeout));
        }
예제 #30
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);
            // }
        }