public void SElementSearchIsLazyAndDoesNotStartOnCreation()
        {
            Given.OpenedEmptyPage();
            var nonExistentElement = Selene.S("#not-existing-element-id");

            Assert.IsNotEmpty(nonExistentElement.ToString());
        }
Esempio n. 2
0
        public void InnerSCollectionSearchWaitsNothing()
        {
            Given.OpenedEmptyPage();
            var elements = Selene.S("div").SS(".will-appear");

            When.WithBody(@"
                <div>
                    <ul>Hello to:
                        <li class='will-appear'>Bob</li>
                        <li class='will-appear' style='display:none'>Kate</li>
                    </ul>
                </div>"
                          );
            When.WithBodyTimedOut(@"
                <div>
                    <ul>Hello to:
                        <li class='will-appear'>Bob</li>
                        <li class='will-appear' style='display:none'>Kate</li>
                        <li class='will-appear'>Bobik</li>
                    </ul>
                </div>",
                                  500
                                  );
            Assert.AreEqual(2, elements.Count);
        }
Esempio n. 3
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));
        }
Esempio n. 4
0
        public void WaitForVisibility_OnActionsLikeClick_AfterFirstWaitingForParentToBeDisplaid()
        {
            Configuration.Timeout         = 1.0;
            Configuration.PollDuringWaits = 0.05;
            Given.OpenedPageWithBody(@"
                <p style='display:none'>
                    <a href='#second' style='display:none'>go to Heading 2</a>
                    <h2 id='second'>Heading 2</h2>
                </p>"
                                     );
            var beforeCall = DateTime.Now;

            Selene.ExecuteScript(@"
                setTimeout(
                    function(){
                        document.getElementsByTagName('p')[0].style = 'display:block';
                    }, 
                    400);
                setTimeout(
                    function(){
                        document.getElementsByTagName('a')[0].style = 'display:block';
                    }, 
                    700);
                "
                                 );

            S("p").Find("a").Click();

            var afterCall = DateTime.Now;

            Assert.Greater(afterCall, beforeCall.AddSeconds(0.7));
            Assert.Less(afterCall, beforeCall.AddSeconds(1.5));
            Assert.IsTrue(Configuration.Driver.Url.Contains("second"));
        }
Esempio n. 5
0
        public static void OpenedEmptyPage()
        {
            String uri = new Uri(Path.Combine(
                                     runFromAssemblyLocation ? Assembly.GetExecutingAssembly().Location : Directory.GetCurrentDirectory(), emptyPage)).AbsoluteUri;

            Selene.Open(uri);
        }
Esempio n. 6
0
        public void YandexTextSearch()
        {
            String emptySearchResponse = "Задан пустой поисковый запрос";

            Selene.GoToUrl("https://yandex.ru/search");
            Selene.S(With.Text(emptySearchResponse)).Should(Have.Text(emptySearchResponse));
        }
Esempio n. 7
0
 // TODO: consider renaming to WithBodyTimedOut
 public static void WithBodyTimedOut(string pageBody, int timeout)
 {
     Selene.ExecuteScript(@"
         setTimeout(
             function(){
                 document.getElementsByTagName('body')[0].innerHTML = " + PrepareBodyHTML(pageBody) + "}, " + timeout + ");");
 }
Esempio n. 8
0
        public static void ExecuteScriptWithTimeout(string script, int timeout)
        {
            // NOTE: script may contain newlines
            Selene.ExecuteScript(@"
	              setTimeout(
	                    function(){ "     + script + @" }, " + timeout + ");");
        }
        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"));
        }
Esempio n. 10
0
 public static void WithBody(string html)
 {
     Selene.ExecuteScript(
         "document.getElementsByTagName('body')[0].innerHTML = \""
         + html.Replace("\n", "").Replace("\r", "").Replace("\"", "\\\"") + "\";"
         );
 }
Esempio n. 11
0
        public void FoundByConditionSElementSearchIsLazyAndDoesNotStartEvenOnFollowingInnerSearch()
        {//TODO: consider testing using FindBy(Have.CssClass("..."))
            Given.OpenedPageWithBody("<p>have no any items nor visible nor hidden</p>");
            var nonExistentElement = Selene.SS(".not-existing").FindBy(Be.Visible).Find("#not-existing-inner");

            Assert.IsNotEmpty(nonExistentElement.ToString());
        }
 public void SCollectionShouldBeEmpty()
 {
     Given.OpenedEmptyPage();
     Selene.SS("li").Should(Be.Empty);
     When.WithBody("<ul>Hello to:<li>Dear Bob</li><li>Lovely Kate</li></ul>");
     Selene.SS("li").ShouldNot(Be.Empty);
 }
Esempio n. 13
0
        public void InnerSCollectionSearchIsUpdatedOnNextActualActionLikeQuestioiningCount()
        {
            Given.OpenedEmptyPage();
            var elements = Selene.S("div").SS(".will-appear");

            When.WithBody(@"
                <div>
                    <ul>Hello to:
                        <li class='will-appear'>Bob</li>
                        <li class='will-appear'>Kate</li>
                    </ul>
                </div>"
                          );
            Assert.AreEqual(2, elements.Count);
            When.WithBody(@"
                <div>
                    <ul>Hello to:
                        <li class='will-appear'>Bob</li>
                        <li class='will-appear'>Kate</li>
                        <li class='will-appear'>Joe</li>
                    </ul>
                </div>"
                          );
            Assert.AreEqual(3, elements.Count);
        }
Esempio n. 14
0
 public static void WithBody(string html)
 {
     Selene.ExecuteScript(
         "document.getElementsByTagName('body')[0].innerHTML = `"
         + html + "`;"
         );
 }
Esempio n. 15
0
        public void InitDriver()
        {
            NSelene.Configuration.Timeout = this.Settings.NSelene.Timeout;

            IWebDriver webDriver;

            if (this.Settings.WebDriver.Local == "chrome")
            {
                new DriverManager().SetUpDriver(new ChromeConfig());
                webDriver = new ChromeDriver();
            }
            else
            {
                var options = new ChromeOptions()
                              .AddGlobal("enableVNC",
                                         this.Settings.WebDriver.Remote.enableVNC)
                              .AddGlobal("enableVideo",
                                         this.Settings.WebDriver.Remote.enableVideo);

                webDriver = new RemoteWebDriver(
                    new Uri(this.Settings.WebDriver.Remote.uri),
                    options);
            }

            Selene.SetWebDriver(webDriver);
        }
        public void SElementSearchIsLazyAndDoesNotStartEvenOnFollowingInnerSearch()
        {
            Given.OpenedEmptyPage();
            var nonExistentElement = Selene.S("#not-existing").Find("#not-existing-inner");

            Assert.IsNotEmpty(nonExistentElement.ToString());
        }
Esempio n. 17
0
 public static void Add(params string[] taskTexts)
 {
     foreach (var text in taskTexts)
     {
         Selene.S("#new-todo").Should(Be.Enabled).SetValue(text).PressEnter();
     }
 }
Esempio n. 18
0
        public void IndexedSElementSearchIsLazyAndDoesNotStartEvenOnFollowingInnerSearch()
        {
            Given.OpenedPageWithBody("<p>have no any items</p>");
            var nonExistentElement = Selene.SS(".not-existing")[10].Find("#not-existing-inner");

            Assert.IsNotEmpty(nonExistentElement.ToString());
        }
Esempio n. 19
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"));
 }
Esempio n. 20
0
 public void SElementShouldBeInDOM()
 {
     Given.OpenedEmptyPage();
     Selene.S("h1").ShouldNot(Be.InDom);
     When.WithBody("<h1 style='display:none'>ku ku</h1>");
     Selene.S("h1").Should(Be.InDom);
 }
Esempio n. 21
0
 public void SElementShouldBeEnabled()
 {
     Given.OpenedPageWithBody("<input type='text' disabled/>");
     Selene.S("input").ShouldNot(Be.Enabled);
     When.WithBody("<input type='text'/>");
     Selene.S("input").Should(Be.Enabled);
 }
Esempio n. 22
0
        public void FoundByConditionSElementSearchIsLazyAndDoesNotStartOnCreation()
        {
            Given.OpenedPageWithBody("<p>have no any items nor visible nor hidden</p>");
            var nonExistentElement = Selene.SS(".not-existing").FindBy(Be.Visible);

            Assert.IsNotEmpty(nonExistentElement.ToString());
        }
        public void InnerSElementSearchIsLazyAndDoesNotStartOnCreation()
        {
            Given.OpenedPageWithBody("<p id='#existing'>Hello!</p>");
            var nonExistentElement = Selene.S("#existing").Find("#not-existing-inner");

            Assert.IsNotEmpty(nonExistentElement.ToString());
        }
Esempio n. 24
0
        public void SeleneWaitTo_HaveNoJsReturned_IsRenderedInError_OnInDomElementsTimeoutFailure()
        {
            Configuration.Timeout         = 0.25;
            Configuration.PollDuringWaits = 0.1;
            Given.OpenedPageWithBody(
                @"
                <p style='display:none'>a</p>
                <p style='display:none'>b</p>
                "
                );
            var beforeCall = DateTime.Now;

            try
            {
                Selene.WaitTo(Have.No.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: not 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).not count = 2", lines);
            //     Assert.Contains("Reason:", lines);
            //     Assert.Contains("actual: count = 2", lines);
            // }
        }
Esempio n. 25
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"));
 }
Esempio n. 26
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!"));
 }
        public void SCollectionSearchIsLazyAndDoesNotStartOnCreation()
        {
            var nonExistingCollection = Selene.SS(".not-existing");

            Assert.IsNotEmpty(nonExistingCollection.ToString());
            // TODO: think on improving... actually it does not tell search is not started
            // it would tell if browser is quited at the moment... but it is not...
        }
        public void SElementSearchIsPostponedUntilActualActionLikeQuestioiningDisplayed()
        {
            Given.OpenedEmptyPage();
            var element = Selene.S("#will-be-existing-element-id");

            When.WithBody(@"<h1 id='will-be-existing-element-id'>Hello kitty:*</h1>");
            Assert.IsTrue(element.Displayed);
        }
Esempio n. 29
0
        public void QuitDriver()
        {
            if (this.Settings.WebDriver.HoldBrowserOpen)
            {
                return;
            }

            Selene.GetWebDriver().Quit();
        }
Esempio n. 30
0
 public static void OpenedEmptyPage()
 {
     Selene.Open(
         new Uri(
             new Uri(Assembly.GetExecutingAssembly().Location),
             "../../../Resources/empty.html"
             ).AbsoluteUri
         );
 }