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"));
        }
Example #2
0
 public static void Visit()
 {
     Selene.GoToUrl("https://todomvc4tasj.herokuapp.com/");
     Selene.WaitFor(Selene.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')"));
 }
Example #3
0
        public void QuitDriver()
        {
            if (this.Settings.WebDriver.HoldBrowserOpen)
            {
                return;
            }

            Selene.GetWebDriver().Quit();
        }
        public void SElementSearchWithXpath()
        {
            // find using wrapped driver methods
            IWebDriver  driver  = Selene.GetWebDriver();
            String      xpath   = "//h1[1]";
            IWebElement element = driver.FindElement(By.XPath(xpath));

            Selene.S(With.XPath(xpath)).Should(Be.InDom);
            StringAssert.AreEqualIgnoringCase(Selene.S(With.XPath(xpath)).TagName, element.TagName);
        }
        //[Test]
        public void JsClick_ClicksOnHiddenElement()
        {
            Given.OpenedPageWithBody(@"
                <a href='#second' style='display:none'>go to Heading 2</a>
                <h2 id='second'>Heading 2</h2>"
                                     );

            //S("a").JsClick();

            Assert.IsTrue(Selene.GetWebDriver().Url.Contains("second"));
        }
        public void JsScrollIntoView()
        {
            Given.OpenedPageWithBody("<input style='margin-top:100cm;' type='text' value='ku ku'/>");
            SeleneElement element = S("input");

            new SeleneDriver(Selene.GetWebDriver()).Should(Have.No.JSReturnedTrue(ELEMENT_IN_VIEEW, element.ActualWebElement));

            element.JsScrollIntoView();

            new SeleneDriver(Selene.GetWebDriver()).Should(Have.JSReturnedTrue(ELEMENT_IN_VIEEW, element.ActualWebElement));
        }
        public void SElementSearchWithText()
        {
            String      searchText      = "Dear";
            String      xpathSearchText = String.Format(@"//*[contains(text(), ""{0}"")]", searchText);
            IWebDriver  webDriver       = Selene.GetWebDriver();
            IWebElement element         = webDriver.FindElement(By.XPath(xpathSearchText));

            StringAssert.Contains(searchText, element.Text);
            Selene.S(NSelene.With.Text(searchText)).Should(Be.InDom);
            Selene.S(NSelene.With.Text(searchText), webDriver).Should(Be.InDom);
        }
Example #8
0
        public void SElementLocalizedTextSearch()
        {
            String name = "абвгдежзийклмнопрстуфхцчшщъыьэюя";

            Given.OpenedPageWithBody(String.Format("<h1>Hello {0}!</h1>", name));
            Selene.S(With.Text(name)).Should(Have.Text(String.Format("Hello {0}!", name)));
            IWebDriver  driver  = Selene.GetWebDriver();
            IWebElement element = driver.FindElement(By.XPath(String.Format("//h1[contains(text(), '{0}')]", name)));

            StringAssert.AreEqualIgnoringCase("h1", element.TagName);
            Selene.S(With.XPath(String.Format("//h1[contains(text(), '{0}')]", name))).Should(Have.Text(String.Format("Hello {0}!", name)));
        }
Example #9
0
        public void FindByCssSelectorAndInnerTextSearch()
        {
            String[] names       = { "Alice", "Bob" };
            String   elementText = String.Format(@"
Hello {0}
and {1}!", names[0], names[1]);

            Given.OpenedPageWithBody(String.Format(@"<h1>{0}</h1>", elementText));
            IWebDriver driver     = Selene.GetWebDriver();
            String     searchText = Regex.Replace(Regex.Replace(elementText, "\r?\n", " "), "^ +", "");

            Selene.S(String.Format("text={0}", searchText)).Should(Be.InDom);
        }
 public void InnerSElementSearchFindsExactlyInsideParentElement()
 {
     Given.OpenedPageWithBody(@"
         <a href='#first' style='display:none'>go to Heading 2</a>
         <p>
             <a href='#second'>go to Heading 2</a>
             <h1 id='first'>Heading 1</h1>
             <h2 id='second'>Heading 2</h2>
         </p>"
                              );
     S("p").Find("a").Click();
     Assert.IsTrue(Selene.GetWebDriver().Url.Contains("second"));
 }
        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 SElementSearchWithTextResultConditons()
        {
            String      searchText      = "Hello there!";
            String      xpathSearchText = String.Format(@"//*[contains(text(), ""{0}"")]", searchText);
            IWebDriver  webDriver       = Selene.GetWebDriver();
            IWebElement element         = webDriver.FindElement(By.XPath(xpathSearchText));

            StringAssert.Contains(searchText, element.Text);

            // verify can use part of the search text in the condition
            Selene.S(NSelene.With.Text(searchText)).Should(Have.Text("Hello"));
            // verify can use the raw text in assertions - more about it in a dedicated class(es) SElementTextMultiLineSearchTests
            Selene.S(NSelene.With.Text("there!"), webDriver).Should(Have.ExactText(searchText));
            Selene.S(NSelene.With.ExactText(element.Text), webDriver).Should(Have.ExactText(element.Text));
        }
 public void WaitForVisibility_OnActionsLikeClick()
 {
     Given.OpenedPageWithBody(@"
         <a href='#second' style='display:none'>go to Heading 2</a>
         <h2 id='second'>Heading 2</h2>"
                              );
     Selene.ExecuteScript(@"
         setTimeout(
             function(){
                 document.getElementsByTagName('a')[0].style = 'display:block';
             }, 
             500);"
                          );
     S("a").Click();
     Assert.IsTrue(Selene.GetWebDriver().Url.Contains("second"));
 }
        public void SElementSearchWithCss()
        {
            // search using wrapped driver methods
            String      cssSelector = @"h1[name = ""greeting""]";
            IWebDriver  driver      = Selene.GetWebDriver();
            IWebElement element     = driver.FindElement(By.CssSelector(cssSelector));

            StringAssert.IsMatch("greeting", element.GetAttribute("name"));

            // search using NSelene methods
            Selene.S(With.Css(cssSelector), driver).Should(Be.InDom);
            Selene.S(With.Css(cssSelector)).Should(Have.Attribute("name", element.GetAttribute("name")));

            // compare old style and new style search results
            StringAssert.IsMatch(Selene.S(cssSelector).GetAttribute("outerHTML"), Selene.S(With.Css(cssSelector)).GetAttribute("outerHTML"));
        }
Example #15
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"));
 }
Example #16
0
        public void SElementMultilineTextSearch()
        {
            String[] names       = { "Alice", "Bob" };
            String   elementText = String.Format(@"
Hello {0}
and {1}!", names[0], names[1]);

            Given.OpenedPageWithBody(String.Format(@"<h1>{0}</h1>", elementText));
            IWebDriver  driver     = Selene.GetWebDriver();
            String      searchText = Regex.Replace(elementText.Replace("\n", " ").Replace("\r", ""), "^ +", "");
            IWebElement element    = driver.FindElement(By.XPath(String.Format("//h1[contains(text(), '{0}')]", searchText)));

            Assert.NotNull(element);
            StringAssert.AreEqualIgnoringCase("h1", element.TagName);
            Selene.S(With.XPath(String.Format("//h1[contains(text(), '{0}')]", searchText))).Should(Be.InDom).Should(Have.Text(String.Format("Hello {0}", names[0])));

            Selene.S(With.Text(names[0])).Should(Have.Text(searchText));
        }
Example #17
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"));
 }
Example #18
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"));
     }
 }
Example #19
0
 public void WaitForVisibility_OnActionsLikeClick_AfterSeleneSSWaiting()
 {// TODO: think on breaking down this test into two, or add one more explicitly testing implicit wait in get
     // todo: SS can't wait;) something is wrong with the test name;)
     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);"
                          );
     SS("a")[1].Click();
     Assert.IsTrue(Selene.GetWebDriver().Url.Contains("second"));
 }
 public void BothNormalAndInnerSElementSearchWaitsForVisibilityOnActionsLikeClick()
 {
     Given.OpenedPageWithBody(@"
         <p style='display:none'>
             <a href='#second' style='display:none'>go to Heading 2</a>
             <h2 id='second'>Heading 2</h2>
         </p>"
                              );
     Selene.ExecuteScript(@"
         setTimeout(
             function(){
                 document.getElementsByTagName('p')[0].style = 'display:block';
             }, 
             500);
        setTimeout(
             function(){
                 document.getElementsByTagName('a')[0].style = 'display:block';
             }, 
             1000);"
                          );
     Selene.S("p").Find("a").Click();
     Assert.IsTrue(Selene.GetWebDriver().Url.Contains("second"));
 }
        public void FailWithTimeout_DuringWaitingForVisibilityOnActionsLikeClick()
        {
            Configuration.Timeout = 0.25;
            Given.OpenedPageWithBody(@"
                <a href='#second' style='display:none'>go to Heading 2</a>
                <h2 id='second'>Heading 2</h2>"
                                     );
            Selene.ExecuteScript(@"
                setTimeout(
                    function(){
                        document.getElementsByTagName('a')[0].style = 'display:block';
                    }, 
                    500);"
                                 );

            // TODO: consider using Assert.Throws<WebDriverTimeoutException>(() => { ... })
            try {
                S("a").Click();
                Assert.Fail("should fail on timeout before can be clicked");
            } catch (WebDriverTimeoutException) {
                Assert.IsFalse(Selene.GetWebDriver().Url.Contains("second"));
            }
        }
        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"));
        }
Example #23
0
        public void MultilineTextSearchIntegrationTest()
        {
            String url         = "http://www.rfbr.ru/rffi/ru/";
            String cssSelector = "div.grants > p";
            // NOTE: The element on the page has a <br/> and a newline
            // removing newline makes the search string one space shorter
            // searchString = "Информация для заявителейи исполнителей проектов";
            // making it difficult to impossible to "predict" the right matching expression
            String searchString = @"Информация для заявителей
и исполнителей проектов";

            Selene.GoToUrl(url);
            // NOTE: slurps exceptions but not in a "Nunit" way
            try {
                // Selene.S(With.Text(searchString)).Should(Be.InDom);
                Selene.S(String.Format("text={0}", searchString.Replace("\n", "").Replace("\r", "")), Selene.GetWebDriver()).Should(Be.InDom);
                // Selene.S(With.Text(searchString)).Should(Have.Text(searchString));
            } catch (TimeoutException e) {
                Console.Error.WriteLine("Exception (ignored) " + e.ToString());
            } catch (NoSuchElementException e) {
                Console.Error.WriteLine("Exception (ignored) " + e.ToString());
            }

            // Break down the element text into single line chunks, successfully find each
            string elementText = (Selene.GetWebDriver()).FindElement(By.CssSelector(cssSelector)).Text;

            elementText = Selene.S(With.Css(cssSelector)).Text;

            foreach (String line in elementText.Split('\n'))
            {
                searchString = line.Replace("\r", "");
                Console.Error.WriteLine("Searching by inner Text fragment:" + searchString);
                Selene.S(With.Text(searchString)).Should(Be.InDom);
                Selene.S(With.Text(searchString)).Should(Have.Text(searchString));
            }
        }
 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 {
         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
     }
 }
Example #25
0
 public void disposeDriver()
 {
     Selene.GetWebDriver().Quit();
 }
 public void TeardownDriver()
 {
     Selene.GetWebDriver().Quit();
 }