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. 2
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. 3
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());
        }
Esempio n. 4
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);
 }
        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 SCollectionSearchUsingWithCssAndLegacy()
        {
            String cssSelector = "li";
            // compare with legacy search results
            ReadOnlyCollection <IWebElement> a = Selene.SS(With.Css(cssSelector)).ActualWebElements;
            ReadOnlyCollection <IWebElement> b = Selene.SS(cssSelector).ActualWebElements;

            Assert.AreEqual(a.Intersect(b).Count(), a.Count);
        }
 public void SCollectionShouldHaveCountAtLeastAndCount()
 {
     Given.OpenedEmptyPage();
     Selene.SS("li").ShouldNot(Have.Count(2));
     When.WithBody("<ul>Hello to:<li>Dear Bob</li><li>Lovely Kate</li></ul>");
     Selene.SS("li").ShouldNot(Have.CountAtLeast(3));
     Selene.SS("li").Should(Have.Count(2));
     Selene.SS("li").Should(Have.CountAtLeast(1));
 }
        public void SCollectionSearchIsPostponedUntilActualActionLikeQuestioiningCount()
        {
            Given.OpenedEmptyPage();
            var elements = Selene.SS(".will-appear");

            When.WithBody(@"
                <ul>Hello to:
                    <li class='will-appear'>Bob</li>
                    <li class='will-appear'>Kate</li>
                </ul>");
            Assert.AreEqual(2, elements.Count);
        }
Esempio n. 10
0
        public void IndexedSElementSearchIsPostponedUntilActualActionLikeQuestioiningValue()
        {
            Given.OpenedEmptyPage();
            var element = Selene.SS("#will-exist>input")[1];

            When.WithBody(@"
                <p id='will-exist'>
                    <input id='ask' type='submit' value='How r u?'></input>
                    <input id='answer' type='submit' value='Good!'></input>
                </p>"
                          );
            Assert.AreEqual("Good!", element.Value);
        }
 public void SCollectionShouldHaveTextsAndExactTexts()
 {
     Given.OpenedPageWithBody("<ul>Hello to:<li>Dear Bob</li><li>Lovely Kate</li></ul>");
     Selene.SS("li").ShouldNot(Have.Texts("Kate", "Bob"));
     Selene.SS("li").ShouldNot(Have.Texts("Bob"));
     Selene.SS("li").ShouldNot(Have.Texts("Bob", "Kate", "Joe"));
     Selene.SS("li").Should(Have.Texts("Bob", "Kate"));
     Selene.SS("li").ShouldNot(Have.ExactTexts("Bob", "Kate"));
     Selene.SS("li").ShouldNot(Have.ExactTexts("Lovely Kate", "Dear Bob"));
     Selene.SS("li").ShouldNot(Have.ExactTexts("Dear Bob"));
     Selene.SS("li").ShouldNot(Have.ExactTexts("Dear Bob", "Lovely Kate", "Funny Joe"));
     Selene.SS("li").Should(Have.ExactTexts("Dear Bob", "Lovely Kate"));
 }
        public void FilteredSCollectionSearchIsPostponedUntilActualActionLikeQuestioiningCount()
        {
            Given.OpenedEmptyPage();
            var elements = Selene.SS("li").FilterBy(Be.Visible);

            When.WithBody(@"
                <ul>Hello to:
                    <li class='will-appear' style='display:none'>Bob</li>
                    <li class='will-appear'>Kate</li>
                </ul>"
                          );
            Assert.AreEqual(1, elements.Count);
        }
Esempio n. 13
0
        public void FoundByConditionSElementSearchIsPostponedUntilActualActionLikeQuestioiningValue()
        {
            Given.OpenedEmptyPage();
            var element = Selene.SS("#will-exist>input").FindBy(Be.Visible);

            When.WithBody(@"
                <p id='will-exist'>
                    <input id='ask' type='submit' value='How r u?' style='display:none'></input>
                    <input id='answer1' type='submit' value='Good!'></input>
                    <input id='answer2' type='submit' value='Great!'></input>
                </p>"
                          );
            Assert.AreEqual("Good!", element.Value);
        }
        public void SCollectionSearchWithCss()
        {
            // search using wrapped driver methods
            String     cssSelector = "ul:nth-of-type(1) li";
            IWebDriver driver      = Selene.GetWebDriver();
            ReadOnlyCollection <IWebElement> elements = driver.FindElements(By.CssSelector(cssSelector));

            Assert.NotNull(elements);

            // search thru NSelene
            SeleneCollection sElementCollection = Selene.SS(With.Css(cssSelector), driver);

            Assert.AreEqual(sElementCollection.Count, elements.Count);
        }
        public void SCollectionGetCountCountsInvisible()
        {
            Given.OpenedEmptyPage();
            var elements = Selene.SS(".will-appear");

            When.WithBody(@"
                <p>
                    <ul>Hello to:
                        <li class='will-appear'>Bob</li>
                        <li class='will-appear' style='display:none'>Kate</li>
                    </ul>
                </p>"
                          );
            Assert.AreEqual(2, elements.Count);
        }
        public void FilteredSCollectionSearchIsUpdatedOnNextActualActionLikeQuestioiningCount()
        {
            Given.OpenedEmptyPage();
            var elements = Selene.SS("li").FilterBy(Be.Visible);

            When.WithBody(@"
                <ul>Hello to:
                    <li class='will-appear' style='display:none'>Miller</li>
                    <li class='will-appear' style='display:none'>Julie Mao</li>
                </ul>"
                          );
            Assert.AreEqual(0, elements.Count);
            Selene.ExecuteScript(@"
                document.getElementsByTagName('li')[0].style = 'display:block';"
                                 );
            Assert.AreEqual(1, elements.Count);
        }
Esempio n. 17
0
        public void InnerSElementSearchIsUpdatedOnNextActualActionLikeQuestioiningValue()
        {
            Given.OpenedEmptyPage();
            var element = Selene.SS("#will-exist>input").FindBy(Be.Visible);

            When.WithBody(@"
                <p id='will-exist'>
                    <input id='ask' type='submit' value='How r u?' style='display:none'></input>
                    <input id='answer1' type='submit' value='Good!'></input>
                </p>"
                          );
            Assert.AreEqual("Good!", element.Value);
            Selene.ExecuteScript(@"
                document.getElementById('answer1').value = 'Great!';"
                                 );
            Assert.AreEqual("Great!", element.Value);
        }
Esempio n. 18
0
 public void IndexedSElementSearchWaitsForVisibilityOnActionsLikeClick()
 {
     Given.OpenedPageWithBody(@"
         <a href='#first'>go to Heading 1</a>
         <a href='#second' style='display:none'>go to Heading 2</a>
         <h1 id='first'>Heading 1</h1>
         <h2 id='second'>Heading 2</h2>"
                              );
     Selene.ExecuteScript(@"
         setTimeout(
             function(){
                 document.getElementsByTagName('a')[1].style = 'display:block';
             }, 
             250);"
                          );
     Selene.SS("a")[1].Click();
     Assert.IsTrue(Selene.GetWebDriver().Url.Contains("second"));
 }
        public void FilteredSCollectionSearchWaitsNothing()
        {
            Given.OpenedEmptyPage();
            var elements = Selene.SS("li").FilterBy(Be.Visible);

            When.WithBodyTimedOut(@"
                <ul>Hello to:
                    <li class='will-appear' style='display:none'>Miller</li>
                    <li class='will-appear' style='display:none'>Julie Mao</li>
                </ul>"
                                  ,
                                  500
                                  );
            When.ExecuteScriptWithTimeout(@"
                document.getElementsByTagName('a')[1].style = 'display:block';
                ", 1000
                                          );
            Assert.AreEqual(0, elements.Count);
        }
Esempio n. 20
0
 public void BothSCollectionAndIndexedSElementSearchWaitsForVisibilityOnActionsLikeClick()
 {// TODO: think on breaking down this test into two, or add one more explicitly testing implicit wait in get
     Given.OpenedEmptyPage();
     When.WithBodyTimedOut(@"
         <a href='#first'>go to Heading 1</a>
         <a href='#second' style='display:none'>go to Heading 2</a>
         <h1 id='first'>Heading 1</h1>
         <h2 id='second'>Heading 2</h2>"
                           ,
                           250
                           );
     Selene.ExecuteScript(@"
        setTimeout(
             function(){
                 document.getElementsByTagName('a')[1].style = 'display:block';
             }, 
             500);"
                          );
     Selene.SS("a")[1].Click();
     Assert.IsTrue(Selene.GetWebDriver().Url.Contains("second"));
 }
Esempio n. 21
0
 public void InnerSElementSearchFailsOnTimeoutDuringWaitingForVisibilityOnActionsLikeClick()
 {
     Configuration.Timeout = 0.25;
     Given.OpenedPageWithBody(@"
         <a href='#first'>go to Heading 1</a>
         <a href='#second' style='display:none'>go to Heading 2</a>
         <h1 id='first'>Heading 1</h1>
         <h2 id='second'>Heading 2</h2>"
                              );
     When.ExecuteScriptWithTimeout(@"
         document.getElementsByTagName('a')[1].style = 'display:block';"
                                   ,
                                   500
                                   );
     try {
         Selene.SS("a")[1].Click();
         Assert.Fail("should fail on timeout before can be clicked");
     } catch (WebDriverTimeoutException) {
         Assert.IsFalse(Selene.GetWebDriver().Url.Contains("second"));
     }
 }
Esempio n. 22
0
 public void BothSCollectionAndFoundByConditionSElementSearchWaitsForVisibilityOnActionsLikeClick()
 {
     Given.OpenedEmptyPage();
     When.WithBodyTimedOut(@"
         <a href='#first' style='display:none'>go to Heading 1</a>
         <a href='#second' style='display:none'>go to Heading 2</a>
         <h1 id='first'>Heading 1</h1>
         <h2 id='second'>Heading 2</h2>"
                           ,
                           250
                           );
     Selene.ExecuteScript(@"
        setTimeout(
             function(){
                 document.getElementsByTagName('a')[1].style = 'display:block';
             }, 
             500);"
                          );
     Selene.SS("a").FindBy(Be.Visible).Click();
     Assert.IsTrue(Selene.Url().Contains("second"));
 }
        public void SCollectionSearchWaitsNothing()
        {
            Given.OpenedEmptyPage();
            var elements = Selene.SS(".will-appear");

            When.WithBody(@"
                <ul>Hello to:
                    <li class='will-appear'>Bob</li>
                    <li class='will-appear' style='display:none'>Kate</li>
                </ul>"
                          );
            When.WithBodyTimedOut(@"
                <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>",
                                  500
                                  );
            Assert.AreEqual(2, elements.Count);
        }
Esempio n. 24
0
        public void FilterTasks()
        {
            Selene.Open("https://todomvc4tasj.herokuapp.com/");

            Selene.WaitTo(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')"));

            Selene.S("#new-todo").SetValue("a").PressEnter();
            Selene.S("#new-todo").SetValue("b").PressEnter();
            Selene.S("#new-todo").SetValue("c").PressEnter();
            Selene.SS("#todo-list>li").Should(Have.ExactTexts("a", "b", "c"));

            Selene.SS("#todo-list>li").FindBy(Have.ExactText("b")).Find(".toggle").Click();

            Selene.S(By.LinkText("Active")).Click();
            Selene.SS("#todo-list>li").FilterBy(Be.Visible).Should(Have.ExactTexts("a", "c"));

            Selene.S(By.LinkText("Completed")).Click();
            Selene.SS("#todo-list>li").FilterBy(Be.Visible).Should(Have.ExactTexts("b"));
        }
Esempio n. 25
0
 public void FoundByConditionSElementSearchFailsOnTimeoutDuringWaitingForVisibilityOnActionsLikeClick()
 {
     Configuration.Timeout = 0.25;
     Given.OpenedPageWithBody(@"
         <a href='#first' style='display:none'>go to Heading 1</a>
         <a href='#second' style='display:none'>go to Heading 2</a>
         <h1 id='first'>Heading 1</h1>
         <h2 id='second'>Heading 2</h2>"
                              );
     Selene.ExecuteScript(@"
         setTimeout(
             function(){
                 document.getElementsByTagName('a')[1].style = 'display:block';
             }, 
             500);"
                          );
     try {
         Selene.SS("a").FindBy(Be.Visible).Click();
         Assert.Fail("should fail on timeout before can be clicked");
     } catch (WebDriverTimeoutException) {
         Assert.IsFalse(Selene.GetWebDriver().Url.Contains("second"));
         //TODO: consider asserting that actually 250ms passed
     }
 }
        public void SeleneCollectionSearchWithXPath()
        {
            // search using wrapped driver methods
            IWebDriver driver = Selene.GetWebDriver();
            // confirm XPath is valid
            String xpath = "//ul/li";
            ReadOnlyCollection <IWebElement> webElements = driver.FindElements(By.XPath(xpath));

            Assert.NotNull(webElements);
            Assert.Greater(webElements.Count, 0);
            StringAssert.IsMatch("li", webElements[0].TagName);

            // search thru NSelene
            SeleneCollection seleWebElements = null;
            By seleneLocator = With.XPath(xpath);

            seleWebElements = Selene.SS(seleneLocator);
            Assert.NotNull(seleWebElements);
            Assert.AreEqual(seleWebElements.Count, webElements.Count);
            StringAssert.IsMatch("li", seleWebElements[0].TagName);
            // exercise NSelene extension methods
            Selene.SS(seleneLocator).Should(Have.CountAtLeast(1));
            Selene.SS(seleneLocator).Should(Have.ExactTexts("Dear Bob", "Dear Frank", "Lovely Kate"));
        }
        public void FilteredSCollectionSearchIsLazyAndDoesNotStartOnCreation()
        {
            var nonExistingCollection = Selene.SS(".will-exist").FilterBy(Be.Visible);

            Assert.IsNotEmpty(nonExistingCollection.ToString());
        }
Esempio n. 28
0
 public void IndexedSElementSearchIsLazyAndDoesNotStartOnCreation()
 {
     Given.OpenedPageWithBody("<p>have no any items</p>");
     var nonExistentElement = Selene.SS(".not-existing")[10];
 }